Jaxx-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
October 2009
- 3 participants
- 80 discussions
r1590 - in branches/jaxx-2.X/jaxx-demo/src/main: java/jaxx/demo/component/jaxx/navigation java/jaxx/demo/component/jaxx/navigation/content resources/i18n
by tchemit@users.nuiton.org 24 Oct '09
by tchemit@users.nuiton.org 24 Oct '09
24 Oct '09
Author: tchemit
Date: 2009-10-24 13:32:31 +0200 (Sat, 24 Oct 2009)
New Revision: 1590
Added:
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUIHandler.java
Modified:
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties
branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties
Log:
amelioration demo du NavigationTreeHandler
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx 2009-10-24 11:31:57 UTC (rev 1589)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx 2009-10-24 11:32:31 UTC (rev 1590)
@@ -26,9 +26,13 @@
<script><![CDATA[
import jaxx.runtime.SwingUtil;
+import jaxx.demo.component.jaxx.navigation.content.*;
private final FullNavigationTreeHelper helper = new FullNavigationTreeHelper();
+private final ContentUIHandler contentUIHandler = new ContentUIHandler();
setContextValue(helper);
+setContextValue(contentUIHandler);
+helper.setTree(this, navigation);
helper.createModel(this);
@Override
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx 2009-10-24 11:31:57 UTC (rev 1589)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx 2009-10-24 11:32:31 UTC (rev 1590)
@@ -18,7 +18,7 @@
<http://www.gnu.org/licenses/lgpl-3.0.html>.
##%*
-->
-<JPanel layout='{new BorderLayout()}' implements='jaxx.runtime.swing.navigation.NavigationContentUI'>
+<ContentUI superGenericType='People'>
<script><![CDATA[
import jaxx.runtime.SwingUtil;
@@ -27,61 +27,27 @@
@Override
public void openUI(NavigationTreeNode node) throws Exception {
- People p = (People) getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this);
+ People p = (People) getHelper().getSelectedBean(this);
log.info("selected people = "+p);
setData(p);
}
-@Override
-public void closeUI(NavigationTreeNode node) throws Exception {
-// nothing to do
-}
-
-String getType(Object data) {
+String getContent(People data) {
if (data == null) {
- return "no type";
- }
- if (data instanceof java.util.List<?>) {
- java.util.List<?> l = (java.util.List<?>) data;
- if (l.isEmpty()) {
- return "Empty collection";
- }
- return "Collection of " + l.size() + " " + l.get(0).getClass().getSimpleName() + "(s)";
- }
- return data.getClass().getSimpleName();
-}
-
-String getContent(Object data) {
- if (data == null) {
return "no content";
}
StringBuilder buffer = new StringBuilder();
- if (data instanceof java.util.List<?>) {
- for (Object o : ((java.util.List<?>)data)) {
- buffer.append(o).append("\n");
- }
- } else {
- buffer.append(data);
- }
+ buffer.append(data);
return buffer.toString();
}
-ImageIcon getImage(Object data) {
- if (data == null) {
- return null;
- }
- if (data instanceof Movie) {
- return SwingUtil.createIcon(((Movie)data).getImage());
- }
- if (data instanceof People) {
- return SwingUtil.createIcon(((People)data).getImage());
- }
- return null;
+ImageIcon getImage(People data) {
+ return data == null? null :SwingUtil.createIcon(data.getImage());
}
- ]]>
+]]>
</script>
- <People id='data' javaBean='(People) getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this)'/>
+ <People id='data' javaBean='null'/>
<JSplitPane id='splitPane'
orientation='{JSplitPane.VERTICAL_SPLIT}'
@@ -92,7 +58,7 @@
<JScrollPane border='{null}'
horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
- <JTextPane border='{new TitledBorder("Content Type : " + getType(getData()))}'
+ <JTextPane border='{new TitledBorder(_("jaxxdemo.navigation.actor.title"))}'
editable='false'
font-size='11'
text='{getContent(getData())}'/>
@@ -108,4 +74,4 @@
</JScrollPane>
</JSplitPane>
-</JPanel>
\ No newline at end of file
+</ContentUI>
\ No newline at end of file
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2009-10-24 11:31:57 UTC (rev 1589)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2009-10-24 11:32:31 UTC (rev 1590)
@@ -18,7 +18,7 @@
<http://www.gnu.org/licenses/lgpl-3.0.html>.
##%*
-->
-<JPanel layout='{new BorderLayout()}' implements='jaxx.runtime.swing.navigation.NavigationContentUI'>
+<ContentUI superGenericType='java.util.List<People>'>
<script><![CDATA[
import jaxx.runtime.SwingUtil;
@@ -29,60 +29,42 @@
@Override
public void openUI(NavigationTreeNode node) throws Exception {
- java.util.List<People> ps = (java.util.List<People>)getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this);
+ java.util.List<People> ps = (java.util.List<People>)getHelper().getSelectedBean(this);
log.info("selected peoples = "+ps.size());
setData(ps);
+ if (ps!=null) {
+ DefaultListModel model = (DefaultListModel) list.getModel();
+ for (People p : ps) {
+ model.addElement(p);
+ }
+ }
}
@Override
public void closeUI(NavigationTreeNode node) throws Exception {
-// nothing to do
+ // clean list model
+ DefaultListModel model = (DefaultListModel) list.getModel();
+ model.removeAllElements();
}
-
-String getType(Object data) {
- if (data == null) {
- return "no type";
- }
- if (data instanceof java.util.List<?>) {
- java.util.List<?> l = (java.util.List<?>) data;
- if (l.isEmpty()) {
- return "Empty collection";
- }
- return "Collection of " + l.size() + " " + l.get(0).getClass().getSimpleName() + "(s)";
- }
- return data.getClass().getSimpleName();
-}
-
-ListModel getModel(java.util.List<People> data) {
-
- DefaultListModel model = new DefaultListModel();
- for (People m : data) {
- model.addElement(m);
- }
- return model;
-}
-
]]>
</script>
- <java.util.List id='data'
- genericType='People'
- javaBean='(java.util.List<People>)getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this)'/>
+ <java.util.List id='data' genericType='People' javaBean='null'/>
- <JScrollPane border='{new TitledBorder("Content Type : " + getType(getData()))}'
+ <JScrollPane border='{new TitledBorder(_("jaxxdemo.navigation.actors.title"))}'
constraints='BorderLayout.CENTER'
columnHeaderView='{toolbar}'
horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
- <JList id='list' model='{getModel(getData())}' cellRenderer='{new DecoratorListCellRenderer(DecoratorUtils.get(People.class.getSimpleName()))}'/>
+ <JList id='list' model='{new DefaultListModel()}' cellRenderer='{new DecoratorListCellRenderer(DecoratorUtils.get(People.class.getSimpleName()))}'/>
</JScrollPane>
<JToolBar id='toolbar' constraints='BorderLayout.SOUTH'
floatable='false'>
<JPanel layout='{new GridLayout(1,0)}'>
- <JButton text='jaxxdemo.action.show' enabled='{list.getSelectedIndex()!=-1}'/>
+ <JButton text='jaxxdemo.action.show' enabled='{list.getSelectedIndex()!=-1}' onActionPerformed='getHandler().selectChild(this, list.getSelectedIndex())'/>
<JButton text='jaxxdemo.action.add'/>
<JButton text='jaxxdemo.action.remove' enabled='{list.getSelectedIndex()!=-1}'/>
</JPanel>
</JToolBar>
-</JPanel>
\ No newline at end of file
+</ContentUI>
\ No newline at end of file
Added: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx (rev 0)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2009-10-24 11:32:31 UTC (rev 1590)
@@ -0,0 +1,52 @@
+<!--
+ *##%
+ jaxx-demo
+ Copyright (C) 2008 - 2009 CodeLutin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ ##%*
+-->
+<JPanel abstract='true'
+ layout='{new BorderLayout()}'
+ genericType='B extends Object'
+ implements='NavigationContentUI'>
+
+ <script><![CDATA[
+import jaxx.runtime.SwingUtil;
+import jaxx.demo.component.jaxx.navigation.*;
+import jaxx.runtime.decorator.DecoratorUtils;
+import jaxx.runtime.decorator.swing.DecoratorListCellRenderer;
+import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.runtime.swing.navigation.NavigationContentUI;
+
+ContentUIHandler getHandler() {
+ return getContextValue(ContentUIHandler.class);
+}
+
+FullNavigationTreeHelper getHelper() {
+ return getContextValue(FullNavigationTreeHelper.class);
+}
+
+public abstract B getData();
+
+public abstract void setData(B data);
+
+@Override
+public void closeUI(NavigationTreeNode node) throws Exception {
+ // nothing to do
+}
+ ]]>
+ </script>
+</JPanel>
\ No newline at end of file
Added: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUIHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUIHandler.java (rev 0)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUIHandler.java 2009-10-24 11:32:31 UTC (rev 1590)
@@ -0,0 +1,28 @@
+package jaxx.demo.component.jaxx.navigation.content;
+
+import java.util.List;
+import jaxx.demo.component.jaxx.navigation.FullNavigationTreeHelper;
+import jaxx.demo.component.jaxx.navigation.Movie;
+import jaxx.demo.component.jaxx.navigation.People;
+import jaxx.runtime.JAXXContext;
+
+/**
+ *
+ * @author chemit
+ */
+public class ContentUIHandler {
+
+ public void selectChild(JAXXContext context, int movieIndex) {
+ FullNavigationTreeHelper helper = context.getContextValue(FullNavigationTreeHelper.class);
+ helper.gotoChildNode(context, movieIndex);
+ }
+
+ public void addMovie(JAXXContext context, Movie movie) {
+ List<Movie> movies = FullNavigationTreeHelper.MOVIES.getContextValue(context);
+ List<People> actors = FullNavigationTreeHelper.ACTORS.getContextValue(context);
+ }
+
+ public void addActor(JAXXContext context, People a, Movie... movies) {
+ List<People> actors = FullNavigationTreeHelper.ACTORS.getContextValue(context);
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUIHandler.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx 2009-10-24 11:31:57 UTC (rev 1589)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx 2009-10-24 11:32:31 UTC (rev 1590)
@@ -18,7 +18,7 @@
<http://www.gnu.org/licenses/lgpl-3.0.html>.
##%*
-->
-<JPanel layout='{new BorderLayout()}' implements='jaxx.runtime.swing.navigation.NavigationContentUI'>
+<ContentUI superGenericType='Movie'>
<script><![CDATA[
import jaxx.runtime.SwingUtil;
@@ -27,61 +27,27 @@
@Override
public void openUI(NavigationTreeNode node) throws Exception {
- Movie m = (Movie) getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this);
- log.info("selected movie = "+m);
+ Movie m = (Movie) getHelper().getSelectedBean(this);
+ log.info("selected movie = " + m);
setData(m);
}
-@Override
-public void closeUI(NavigationTreeNode node) throws Exception {
-// nothing to do
-}
-
-String getType(Object data) {
+String getContent(Movie data) {
if (data == null) {
- return "no type";
- }
- if (data instanceof java.util.List<?>) {
- java.util.List<?> l = (java.util.List<?>) data;
- if (l.isEmpty()) {
- return "Empty collection";
- }
- return "Collection of " + l.size() + " " + l.get(0).getClass().getSimpleName() + "(s)";
- }
- return data.getClass().getSimpleName();
-}
-
-String getContent(Object data) {
- if (data == null) {
return "no content";
}
StringBuilder buffer = new StringBuilder();
- if (data instanceof java.util.List<?>) {
- for (Object o : ((java.util.List<?>)data)) {
- buffer.append(o).append("\n");
- }
- } else {
- buffer.append(data);
- }
+ buffer.append(data);
return buffer.toString();
}
-ImageIcon getImage(Object data) {
- if (data == null) {
- return null;
- }
- if (data instanceof Movie) {
- return SwingUtil.createIcon(((Movie)data).getImage());
- }
- if (data instanceof People) {
- return SwingUtil.createIcon(((People)data).getImage());
- }
- return null;
+ImageIcon getImage(Movie data) {
+ return data == null? null :SwingUtil.createIcon(data.getImage());
}
- ]]>
+]]>
</script>
- <Movie id='data' javaBean='(Movie) getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this)'/>
+ <Movie id='data' javaBean='null'/>
<JSplitPane id='splitPane'
orientation='{JSplitPane.VERTICAL_SPLIT}'
@@ -92,7 +58,7 @@
<JScrollPane border='{null}'
horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
- <JTextPane border='{new TitledBorder("Content Type : " + getType(getData()))}'
+ <JTextPane border='{new TitledBorder(_("jaxxdemo.navigation.movie.title"))}'
editable='false'
font-size='11'
text='{getContent(getData())}'/>
@@ -108,4 +74,4 @@
</JScrollPane>
</JSplitPane>
-</JPanel>
\ No newline at end of file
+</ContentUI>
\ No newline at end of file
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2009-10-24 11:31:57 UTC (rev 1589)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2009-10-24 11:32:31 UTC (rev 1590)
@@ -18,7 +18,7 @@
<http://www.gnu.org/licenses/lgpl-3.0.html>.
##%*
-->
-<JPanel layout='{new BorderLayout()}' implements='jaxx.runtime.swing.navigation.NavigationContentUI'>
+<ContentUI superGenericType='java.util.List<Movie>'>
<script><![CDATA[
import jaxx.runtime.SwingUtil;
@@ -29,58 +29,42 @@
@Override
public void openUI(NavigationTreeNode node) throws Exception {
- java.util.List<Movie> ms = (java.util.List<Movie>)getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this);
+ java.util.List<Movie> ms = (java.util.List<Movie>)getHelper().getSelectedBean(this);
log.info("selected movies = "+ms.size());
setData(ms);
+ if (ms != null) {
+ DefaultListModel model = (DefaultListModel) list.getModel();
+ for (Movie m : ms) {
+ model.addElement(m);
+ }
+ }
}
@Override
public void closeUI(NavigationTreeNode node) throws Exception {
-// nothing to do
+ // clean list model
+ DefaultListModel model = (DefaultListModel) list.getModel();
+ model.removeAllElements();
}
-String getType(Object data) {
- if (data == null) {
- return "no type";
- }
- if (data instanceof java.util.List<?>) {
- java.util.List<?> l = (java.util.List<?>) data;
- if (l.isEmpty()) {
- return "Empty collection";
- }
- return "Collection of " + l.size() + " " + l.get(0).getClass().getSimpleName() + "(s)";
- }
- return data.getClass().getSimpleName();
-}
-
-ListModel getModel(java.util.List<Movie> data) {
- DefaultListModel model = new DefaultListModel();
- for (Movie m : data) {
- model.addElement(m);
- }
- return model;
-}
-
]]>
</script>
- <java.util.List id='data'
- genericType='Movie'
- javaBean='(java.util.List<Movie>)getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this)'/>
+ <java.util.List id='data' genericType='Movie' javaBean='null'/>
- <JScrollPane border='{new TitledBorder("Content Type : " + getType(getData()))}'
+ <JScrollPane border='{new TitledBorder(_("jaxxdemo.navigation.movies.title"))}'
constraints='BorderLayout.CENTER'
columnHeaderView='{toolbar}'
horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
- <JList id='list' model='{getModel(getData())}' cellRenderer='{new DecoratorListCellRenderer(DecoratorUtils.get(Movie.class.getSimpleName()))}'/>
+ <JList id='list' model='{new DefaultListModel()}' cellRenderer='{new DecoratorListCellRenderer(DecoratorUtils.get(Movie.class.getSimpleName()))}'/>
</JScrollPane>
<JToolBar id='toolbar' opaque='false' constraints='BorderLayout.SOUTH'
floatable='false'>
<JPanel layout='{new GridLayout(1,0)}'>
- <JButton text='jaxxdemo.action.show' enabled='{list.getSelectedIndex()!=-1}'/>
+ <JButton text='jaxxdemo.action.show' enabled='{list.getSelectedIndex()!=-1}' onActionPerformed='getHandler().selectChild(this, list.getSelectedIndex())'/>
<JButton text='jaxxdemo.action.add'/>
<JButton text='jaxxdemo.action.remove' enabled='{list.getSelectedIndex()!=-1}'/>
</JPanel>
</JToolBar>
-</JPanel>
\ No newline at end of file
+</ContentUI>
\ No newline at end of file
Modified: branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties 2009-10-24 11:31:57 UTC (rev 1589)
+++ branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties 2009-10-24 11:32:31 UTC (rev 1590)
@@ -159,6 +159,10 @@
jaxxdemo.menu.help=
jaxxdemo.message.config.loaded=Configuration of JAXXDemo v. %1$s loaded.
jaxxdemo.message.goto.site=Go to JAXXDemo Web site
+jaxxdemo.navigation.actor.title=
+jaxxdemo.navigation.actors.title=
+jaxxdemo.navigation.movie.title=
+jaxxdemo.navigation.movies.title=
jaxxdemo.numbereditor.autoPopup=
jaxxdemo.numbereditor.configuration=
jaxxdemo.numbereditor.model=
Modified: branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties 2009-10-24 11:31:57 UTC (rev 1589)
+++ branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties 2009-10-24 11:32:31 UTC (rev 1590)
@@ -159,6 +159,10 @@
jaxxdemo.menu.help=Aide
jaxxdemo.message.config.loaded=Configuration de JAXX Demo v. %1$s charg\u00E9e.
jaxxdemo.message.goto.site=Acc\u00E9der au site de JAXX Demo (%1$s)
+jaxxdemo.navigation.actor.title=
+jaxxdemo.navigation.actors.title=
+jaxxdemo.navigation.movie.title=
+jaxxdemo.navigation.movies.title=
jaxxdemo.numbereditor.autoPopup=Affichage automatique popup
jaxxdemo.numbereditor.configuration=Configuration
jaxxdemo.numbereditor.model=R\u00E9sultat
1
0
Author: tchemit
Date: 2009-10-24 13:31:57 +0200 (Sat, 24 Oct 2009)
New Revision: 1589
Added:
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaArgument.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaElement.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaField.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaFieldComparator.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaFile.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaMethod.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaMethodComparator.java
branches/jaxx-2.X/jaxx-compiler/src/main/resources/META-INF/services/jaxx.compiler.decorators.CompiledObjectDecorator
branches/jaxx-2.X/jaxx-compiler/src/main/resources/META-INF/services/jaxx.compiler.types.TypeConverter
Removed:
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaArgument.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaField.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaFile.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaMethod.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/CompiledObjectDecoratorManager.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/GeneratorManager.java
Modified:
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataBinding.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataSource.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXProfile.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/StylesheetHelper.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/BoxedCompiledObjectDecorator.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/CompiledObjectDecorator.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/Generator.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/JAXXObjectGenerator.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/SwingGenerator.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/ValidatorGenerator.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorLoader.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/reflect/JavaFileParser.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/spi/DefaultInitializer.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/TagManager.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXComboBoxHandler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXListHandler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXTreeHandler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TabHandler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tools/PrintTagInfo.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tools/jaxxcapture/handlers/ObjectHandler.java
branches/jaxx-2.X/jaxx-compiler/src/test/java/jaxx/compiler/JavaMethodTest.java
branches/jaxx-2.X/jaxx-compiler/src/test/java/jaxx/compiler/tags/TagManagerTest.java
Log:
- Evolution #100: am?\195?\169lioration du design du compilateur
- Evolution #99: Am?\195?\169liorer le code g?\195?\169n?\195?\169r?\195?\169
- Evolution #98: les objets JAXX sont serializable
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -11,7 +11,6 @@
import jaxx.compiler.tags.DefaultComponentHandler;
import jaxx.compiler.tags.TagHandler;
import jaxx.compiler.tags.TagManager;
-import jaxx.compiler.types.TypeManager;
import java.awt.Container;
import java.lang.reflect.Method;
@@ -389,8 +388,8 @@
ClassDescriptor listenerClass = addMethod.getParameterTypes()[0];
return getJavaCode() + '.' + addMethod.getName() + "((" + JAXXCompiler.getCanonicalName(listenerClass) +
") jaxx.runtime.Util.getEventListener(" + JAXXCompiler.getCanonicalName(listenerClass) + ".class, " +
- TypeManager.getJavaCode(handler.getListenerMethod().getName()) + ", " + compiler.getRootObject().getJavaCode() + ", " +
- TypeManager.getJavaCode(compiler.getEventHandlerMethodName(handler)) + "));" + JAXXCompiler.getLineSeparator();
+ compiler.getJavaCode(handler.getListenerMethod().getName()) + ", " + compiler.getRootObject().getJavaCode() + ", " +
+ compiler.getJavaCode(compiler.getEventHandlerMethodName(handler)) + "));" + JAXXCompiler.getLineSeparator();
}
/**
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataBinding.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataBinding.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataBinding.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -4,8 +4,6 @@
*/
package jaxx.compiler;
-import jaxx.compiler.types.TypeManager;
-
/**
* Represents a data binding in a JAXX file. <code>DataBinding</code> uses {@link DataSource} to
* track changes to a source expression and update the destination.
@@ -55,7 +53,7 @@
*/
public boolean compile(boolean quickNoDependencies) throws CompilerException {
// DataSource.compile handles all of the listener additions
- boolean result = dataSource.compile("new jaxx.runtime.DataBindingListener(" + compiler.getRootObject().getJavaCode() + ", " + TypeManager.getJavaCode(id) + ")");
+ boolean result = dataSource.compile("new jaxx.runtime.DataBindingListener(" + compiler.getRootObject().getJavaCode() + ", " + compiler.getJavaCode(id) + ")");
if (!result && quickNoDependencies) {
if (!dest.endsWith(".layout")) // layout is specially handled early in the chain
@@ -69,7 +67,7 @@
} else {
compiler.appendProcessDataBinding(" ");
}
- compiler.appendProcessDataBinding("if (" + TypeManager.getJavaCode(id) + ".equals($dest)) {" + JAXXCompiler.getLineSeparator());
+ compiler.appendProcessDataBinding("if (" + compiler.getJavaCode(id) + ".equals($dest)) {" + JAXXCompiler.getLineSeparator());
String objectCode = dataSource.getObjectCode();
if (objectCode != null) {
compiler.appendProcessDataBinding(" if (" + objectCode + " != null) {" + JAXXCompiler.getLineSeparator());
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataSource.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataSource.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataSource.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -4,6 +4,7 @@
*/
package jaxx.compiler;
+import jaxx.compiler.io.JavaField;
import jaxx.compiler.parser.java.JavaParser;
import jaxx.compiler.parser.java.JavaParserConstants;
import jaxx.compiler.parser.java.JavaParserTreeConstants;
@@ -99,7 +100,7 @@
if (dependencySymbols.size() > 0) {
//TC 20081108 prefer add a real JavaField instead of raw code
//compiler.appendBodyCode("private PropertyChangeListener " + id + " = " + propertyChangeListenerCode + ";\n");
- compiler.addSimpleField(new JavaField(Modifier.PRIVATE, PropertyChangeListener.class.getName(), autoId, propertyChangeListenerCode));
+ compiler.addSimpleField(new JavaField(Modifier.PRIVATE, PropertyChangeListener.class.getName(), autoId,false, propertyChangeListenerCode));
}
compileListeners();
@@ -390,8 +391,9 @@
this.objectCode = objectCode;
if (!dependencySymbols.contains(dependencySymbol)) {
dependencySymbols.add(dependencySymbol);
+ String eol = JAXXCompiler.getLineSeparator();
if (objectCode != null) {
- addListenerCode.append("if (").append(objectCode).append(" != null) {").append(JAXXCompiler.getLineSeparator());
+ addListenerCode.append("if (").append(objectCode).append(" != null) {").append(eol);
addListenerCode.append(" ");
}
addListenerCode.append(" ").append(addCode);
@@ -400,7 +402,7 @@
}
if (objectCode != null) {
- removeListenerCode.append("if (").append(objectCode).append(" != null) {").append(JAXXCompiler.getLineSeparator());
+ removeListenerCode.append("if (").append(objectCode).append(" != null) {").append(eol);
removeListenerCode.append(" ");
}
removeListenerCode.append(" ").append(removeCode);
@@ -412,12 +414,13 @@
private void compileListeners() {
String javaCodeId = TypeManager.getJavaCode(id);
+ String eol = JAXXCompiler.getLineSeparator();
if (addListenerCode.length() > 0) {
if (compiler.haveApplyDataBinding()) {
compiler.appendApplyDataBinding(" else ");
}
- compiler.appendApplyDataBinding("if (" + javaCodeId + ".equals($binding)) {" + JAXXCompiler.getLineSeparator());
- compiler.appendApplyDataBinding(" " + addListenerCode + JAXXCompiler.getLineSeparator());
+ compiler.appendApplyDataBinding("if (" + javaCodeId + ".equals($binding)) {" + eol);
+ compiler.appendApplyDataBinding(" " + addListenerCode + eol);
compiler.appendApplyDataBinding("}");
//if (compiler.applyDataBinding.length() > 0)
// compiler.applyDataBinding.append("else ");
@@ -430,8 +433,8 @@
if (compiler.haveRemoveDataBinding()) {
compiler.appendRemoveDataBinding(" else ");
}
- compiler.appendRemoveDataBinding("if (" + javaCodeId + ".equals($binding)) {" + JAXXCompiler.getLineSeparator());
- compiler.appendRemoveDataBinding(" " + removeListenerCode + JAXXCompiler.getLineSeparator());
+ compiler.appendRemoveDataBinding("if (" + javaCodeId + ".equals($binding)) {" + eol);
+ compiler.appendRemoveDataBinding(" " + removeListenerCode + eol);
compiler.appendRemoveDataBinding("}");
//if (compiler.removeDataBinding.length() > 0)
// compiler.removeDataBinding.append("else ");
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -4,8 +4,10 @@
*/
package jaxx.compiler;
+import jaxx.compiler.io.JavaMethod;
+import jaxx.compiler.io.JavaField;
+import jaxx.compiler.io.JavaFile;
import jaxx.compiler.decorators.CompiledObjectDecorator;
-import jaxx.compiler.decorators.CompiledObjectDecoratorManager;
import jaxx.compiler.generators.Generator;
import jaxx.compiler.parser.java.ParseException;
import jaxx.compiler.reflect.ClassDescriptor;
@@ -63,6 +65,7 @@
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import jaxx.compiler.types.TypeManager;
/**
* Compiles JAXX files into Java classes.
@@ -71,7 +74,9 @@
*/
public class JAXXCompiler {
- /** log */
+ /**
+ * Logger
+ */
protected static final Log log = LogFactory.getLog(JAXXCompiler.class);
/**
* True to throw exceptions when we encounter unresolvable classes, false to ignore.
@@ -96,10 +101,10 @@
* The unique object handler used in first pass
*/
protected final DefaultObjectHandler firstPassClassTagHandler;
- /**
- * list of static imports
- */
- protected List<String> staticImports = new ArrayList<String>();
+// /**
+// * list of static imports
+// */
+// protected List<String> staticImports = new ArrayList<String>();
/*---------------------------------------------------------------------------------*/
/*-- compiler fields --------------------------------------------------------------*/
@@ -273,15 +278,53 @@
* default decodator to use if none specified
*/
protected CompiledObjectDecorator defaultDecorator;
+ /**
+ * engine which references this compiler (can be null if compiler is standalone)
+ */
+ protected final JAXXEngine engine;
/*---------------------------------------------------------------------------------*/
/*-- Constructor methods ----------------------------------------------------------*/
/*---------------------------------------------------------------------------------*/
- protected JAXXCompiler(ClassLoader classLoader) {
-
+// protected JAXXCompiler(ClassLoader classLoader) {
+//
+// this.firstPassClassTagHandler = new DefaultObjectHandler(ClassDescriptorLoader.getClassDescriptor(Object.class));
+// this.configuration = new DefaultCompilerConfiguration();
+// this.classLoader = classLoader;
+//// this.staticImports = Arrays.asList(new String[]{
+//// "java.awt.*",
+//// "java.awt.event.*",
+//// "java.beans.*",
+//// "java.io.*",
+//// "java.lang.*",
+//// "java.util.*",
+//// "javax.swing.*",
+//// "javax.swing.border.*",
+//// "javax.swing.event.*",
+//// "jaxx.runtime.swing.JAXXButtonGroup",
+//// "jaxx.runtime.swing.HBox",
+//// "jaxx.runtime.swing.VBox",
+//// "jaxx.runtime.swing.Table",
+//// "static org.nuiton.i18n.I18n._",
+//// "static jaxx.runtime.Util.createImageIcon"
+//// });
+// addImport("java.lang.*");
+// }
+ /**
+ * Creates a new JAXXCompiler.
+ *
+ * @param engine engine which use the compiler (could be null if not attach to any engine)
+ * @param baseDir classpath location
+ * @param src location of file to compile
+ * @param outputClassName the out file name
+ * @param configuration configuration to pass to javac
+ * @param defaultImports list of default imports to add to java files
+ */
+ public JAXXCompiler(JAXXEngine engine, File baseDir, File src, String outputClassName, CompilerConfiguration configuration, List<String> defaultImports) {
+ this.engine = engine;
+ this.baseDir = baseDir;
+ this.src = src;
this.firstPassClassTagHandler = new DefaultObjectHandler(ClassDescriptorLoader.getClassDescriptor(Object.class));
- this.configuration = new DefaultCompilerConfiguration();
- this.classLoader = classLoader;
// this.staticImports = Arrays.asList(new String[]{
// "java.awt.*",
// "java.awt.event.*",
@@ -299,55 +342,29 @@
// "static org.nuiton.i18n.I18n._",
// "static jaxx.runtime.Util.createImageIcon"
// });
- addImport("java.lang.*");
- }
-
- /**
- * Creates a new JAXXCompiler.
- *
- * @param baseDir classpath location
- * @param src location of file to compile
- * @param outputClassName the out file name
- * @param configuration configuration to pass to javac
- */
- public JAXXCompiler(File baseDir, File src, String outputClassName, CompilerConfiguration configuration) {
- this.baseDir = baseDir;
- this.src = src;
- this.firstPassClassTagHandler = new DefaultObjectHandler(ClassDescriptorLoader.getClassDescriptor(Object.class));
- this.staticImports = Arrays.asList(new String[]{
- "java.awt.*",
- "java.awt.event.*",
- "java.beans.*",
- "java.io.*",
- "java.lang.*",
- "java.util.*",
- "javax.swing.*",
- "javax.swing.border.*",
- "javax.swing.event.*",
- "jaxx.runtime.swing.JAXXButtonGroup",
- "jaxx.runtime.swing.HBox",
- "jaxx.runtime.swing.VBox",
- "jaxx.runtime.swing.Table",
- "static org.nuiton.i18n.I18n._",
- "static jaxx.runtime.Util.createImageIcon"
- });
sourceFiles.push(src);
this.outputClassName = outputClassName;
this.configuration = configuration;
- addImport(outputClassName.substring(0, outputClassName.lastIndexOf(".") + 1) + "*");
- for (Object staticImport : staticImports) {
- addImport((String) staticImport);
+ if (outputClassName != null) {
+ addImport(outputClassName.substring(0, outputClassName.lastIndexOf(".") + 1) + "*");
}
- // add extra imports from configuration
- if (configuration.getExtraImports() != null) {
- for (String extraImport : configuration.getExtraImports()) {
- addImport(extraImport);
+ if (defaultImports != null) {
+ for (Object staticImport : defaultImports) {
+ addImport((String) staticImport);
}
}
- defaultDecorator = CompiledObjectDecoratorManager.getDecorator(configuration.getDefaultDecoratorClass());
- if (defaultDecorator == null) {
- log.error("could not find default decorator : " + configuration.getDefaultDecoratorClass());
- throw new IllegalArgumentException("could not find default decorator : " + configuration.getDefaultDecoratorClass());
+ if (configuration != null) {
+ // add extra imports from configuration
+ if (configuration.getExtraImports() != null) {
+ for (String extraImport : configuration.getExtraImports()) {
+ addImport(extraImport);
+ }
+ }
+ defaultDecorator = engine.getDecorator(configuration.getDefaultDecoratorClass());
+ if (defaultDecorator == null) {
+ log.error("could not find default decorator : " + configuration.getDefaultDecoratorClass());
+ throw new IllegalArgumentException("could not find default decorator : " + configuration.getDefaultDecoratorClass());
+ }
}
}
@@ -547,7 +564,7 @@
}
public void registerCompiledObject(CompiledObject object) {
- assert JAXXCompilerLaunchor.get().symbolTables.values().contains(symbolTable) : "attempting to register CompiledObject before pass 1 is complete";
+ assert engine.symbolTables.values().contains(symbolTable) : "attempting to register CompiledObject before pass 1 is complete";
if (root == null) {
root = object;
}
@@ -569,7 +586,7 @@
public CompiledObject getCompiledObject(String id) {
runInitializers();
- assert JAXXCompilerLaunchor.get().symbolTables.values().contains(symbolTable) : "attempting to retrieve CompiledObject before pass 1 is complete";
+ assert engine.symbolTables.values().contains(symbolTable) : "attempting to retrieve CompiledObject before pass 1 is complete";
return objects.get(id);
}
@@ -600,6 +617,16 @@
}
}
+ public String getJavaCode(Object object) {
+ String result = TypeManager.getJavaCode(object);
+ return result;
+ }
+
+ public Object convertFromString(String string, Class<?> type) {
+ Object result = TypeManager.convertFromString(string, type);
+ return result;
+ }
+
/*---------------------------------------------------------------------------------*/
/*-- DataBinding methods ----------------------------------------------------------*/
/*---------------------------------------------------------------------------------*/
@@ -798,7 +825,10 @@
System.err.print(":" + ((sourceFiles.size() == 1) ? Integer.parseInt(lineNumber) + lineOffset : lineOffset + 1));
}
System.err.println(": Warning: " + warning);
- JAXXCompilerLaunchor.get().warningCount++;
+ if (engine != null) {
+ engine.warningCount++;
+ }
+// JAXXEngine.get().warningCount++;
}
public void reportError(String error) {
@@ -862,7 +892,10 @@
System.err.print(":" + lineNumber);
}
System.err.println(": " + error);
- JAXXCompilerLaunchor.get().errorCount++;
+ if (engine != null) {
+ engine.errorCount++;
+ }
+// JAXXEngine.get().errorCount++;
failed = true;
}
@@ -968,20 +1001,6 @@
classLoader = configuration.getClassLoader();
} else {
throw new NullPointerException("compiler configuration requires a classLoader! :\n" + configuration);
-// String classPath = configuration.getClassPath();
-// if (classPath == null) {
-// classPath = ".";
-// }
-// String[] paths = classPath.split(File.pathSeparator);
-// URL[] urls = new URL[paths.length];
-// for (int i = 0; i < paths.length; i++) {
-// try {
-// urls[i] = new File(paths[i]).toURI().toURL();
-// } catch (MalformedURLException e) {
-// throw new RuntimeException(e);
-// }
-// }
-// classLoader = new URLClassLoader(urls, getClass().getClassLoader());
}
}
@@ -1153,7 +1172,8 @@
public void addDependencyClass(String className) {
- if (!JAXXCompilerLaunchor.get().jaxxFileClassNames.contains(className)) {
+// if (!JAXXEngine.get().jaxxFileClassNames.contains(className)) {
+ if (!engine.jaxxFileClassNames.contains(className)) {
URL jaxxURL = getClassLoader().getResource(className.replace('.', '/') + ".jaxx");
URL classURL = getClassLoader().getResource(className.replace('.', '/') + ".class");
if (jaxxURL != null && classURL != null) {
@@ -1178,11 +1198,14 @@
assert jaxxFile.getName().equalsIgnoreCase(className.substring(className.lastIndexOf(".") + 1) + ".jaxx") :
"expecting file name to match " + className + ", but found " + jaxxFile.getName();
if (jaxxFile.getName().equals(className.substring(className.lastIndexOf(".") + 1) + ".jaxx")) { // check case match
- if (JAXXCompilerLaunchor.get().currentPass != JAXXCompilerLaunchor.LifeCycle.compile_first_pass) {
+// if (JAXXEngine.get().currentPass != JAXXEngine.LifeCycle.compile_first_pass) {
+ if (engine.currentPass != JAXXEngine.LifeCycle.compile_first_pass) {
throw new AssertionError("Internal error: adding dependency class " + className + " during second compilation pass");
}
- JAXXCompilerLaunchor.get().jaxxFileClassNames.add(className);
- JAXXCompilerLaunchor.get().jaxxFiles.add(jaxxFile);
+// JAXXEngine.get().jaxxFileClassNames.add(className);
+// JAXXEngine.get().jaxxFiles.add(jaxxFile);
+ engine.jaxxFileClassNames.add(className);
+ engine.jaxxFiles.add(jaxxFile);
}
}
}
@@ -1406,7 +1429,7 @@
for (Generator generator : generatorIterator) {
generator.prepareJavaFile(compiledObject, this, javaFile, packageName, simpleClassName);
}
- out.println(javaFile.toString(getLineSeparator()));
+ out.println(javaFile.toString());
out.close();
} catch (RuntimeException e) {
// file could not be generated, so delete it...
@@ -1601,4 +1624,8 @@
throw new RuntimeException(ex);
}
}
+
+ public JAXXEngine getEngine() {
+ return engine;
+ }
}
Deleted: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,429 +0,0 @@
-package jaxx.compiler;
-
-import jaxx.compiler.generators.Generator;
-import jaxx.compiler.spi.Initializer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.File;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-import jaxx.compiler.generators.GeneratorManager;
-
-/** @author chemit */
-public class JAXXCompilerLaunchor {
-
- /** log */
- protected static final Log log = LogFactory.getLog(JAXXCompilerLaunchor.class);
-
- protected enum LifeCycle {
-
- init,// state before compilation
- compile_first_pass, // state when first pass of compilation
- compile_second_pass, // state when second pass of compilation
- stylesheet_pass, // state when applygin stylesheet phase after compilation
- generate_pass, // state when generation phase
- profile_pass // state when profile
- }
- /** shared instance of unique launchor at a givne time. */
- protected static JAXXCompilerLaunchor singleton;
-
- /**
- * Create a new empty launchor and set it as current launchor accessible via method {@link #get()}
- *
- * @return the new instanciated launchor
- */
- public static synchronized JAXXCompilerLaunchor newLaunchor() {
- return newLaunchor((File[]) null, null, null);
- }
-
- /**
- * Create a new launchor and set it as current launchor accessible via method {@link #get()}.
- * <p/>
- * The launchor will be prepared to compile a set of files, expressed as paths relative to a base directory.
- * The class names of the compiled files are derived from the relative path strings
- * (e.g. "example/Foo.jaxx" compiles into a class named "example.Foo").
- *
- * @param base the directory against which to resolve relative paths
- * @param relativePaths a list of relative paths to .jaxx files being compiled
- * @param configuration the compiler configuration to use
- * @return the new instanciated launchor
- */
- public static synchronized JAXXCompilerLaunchor newLaunchor(File base, String[] relativePaths, CompilerConfiguration configuration) {
- File[] files = new File[relativePaths.length];
- String[] classNames = new String[relativePaths.length];
- for (int i = 0; i < files.length; i++) {
- files[i] = new File(base, relativePaths[i]);
- classNames[i] = relativePaths[i].substring(0, relativePaths[i].lastIndexOf("."));
- classNames[i] = classNames[i].replace(File.separatorChar, '.');
- classNames[i] = classNames[i].replace('/', '.');
- classNames[i] = classNames[i].replace('\\', '.');
- classNames[i] = classNames[i].replace(':', '.');
- }
- return newLaunchor(files, classNames, configuration);
- }
-
- /**
- * Create a new launchor and set it as current launchor accessible via method {@link #get()}.
- * <p/>
- * The launchor will be prepared to compile a set of files, with the class names specified explicitly.
- * The class compiled from files[i] will be named classNames[i].
- *
- * @param files the .jaxx files to compile
- * @param classNames the names of the classes being compiled
- * @param configuration the compiler configuration to use
- * @return the new instanciated launchor
- */
- public static synchronized JAXXCompilerLaunchor newLaunchor(File[] files, String[] classNames, CompilerConfiguration configuration) {
- if (singleton != null) {
- singleton.reset();
- }
- singleton = new JAXXCompilerLaunchor(files, classNames, configuration);
- return singleton;
- }
-
- /**
- * @return the current launchor
- * @throws NullPointerException if no launchor was registred via a <code>newLaunchor-like</code> method.
- */
- public static JAXXCompilerLaunchor get() throws NullPointerException {
- if (singleton == null) {
- throw new NullPointerException("no launchor was registred via newLaunchor method");
- }
- return singleton;
- }
-
- /** @return <code> if there is a launchor registred, <code>false</code> otherwise. */
- public static boolean isRegistred() {
- return singleton != null;
- }
-
- /**
- * Load the {@link Initializer} services found via the{@link ServiceLoader} mecanism.
- *
- * @param verbose <ocde>true</code> to print initializers
- */
- public static void loadLibraries(boolean verbose) {
- //BeanInfoUtil.reset();
- ClassLoader classloader = Thread.currentThread().getContextClassLoader();
- if (verbose) {
- log.info("with cl " + classloader);
- }
- ServiceLoader<Initializer> loader = ServiceLoader.load(Initializer.class, classloader);
- for (Initializer initializer : loader) {
- if (verbose) {
- log.info("load initializer " + initializer);
- }
- initializer.initialize();
- }
- }
- /** configuration of the launchor and underlines compilers */
- protected CompilerConfiguration configuration;
- /** original list of files to compile */
- protected final File[] files;
- /** original list of classes to compile */
- protected final String[] classNames;
- /** Files to be treated while compilation. */
- protected List<File> jaxxFiles = new ArrayList<File>();
- /** Class names corresponding to the files in the jaxxFiles list. */
- protected List<String> jaxxFileClassNames = new ArrayList<String>();
- /** Maps the names of classes being compiled to the compiler instance handling the compilation. */
- protected Map<String, JAXXCompiler> compilers = new HashMap<String, JAXXCompiler>();
- /** Maps the names of classes being compiled to their symbol tables (created after the first compiler pass). */
- protected Map<File, SymbolTable> symbolTables = new HashMap<File, SymbolTable>();
- protected LifeCycle currentPass;
- protected int errorCount;
- protected int warningCount;
- protected int compilerCount;
- protected JAXXProfile profiler;
-
- protected JAXXCompilerLaunchor(File[] files, String[] classNames, CompilerConfiguration options) {
- this.configuration = options == null ? new DefaultCompilerConfiguration() : options;
- this.files = files;
- this.classNames = classNames;
- if (this.configuration.isVerbose()) {
- log.info("files : " + Arrays.toString(files));
- }
- if (this.configuration.isProfile()) {
- profiler = new JAXXProfile();
- }
- }
-
- public void init() {
- // forces static initializer to run if it hasn't yet
- }
-
- /** Resets all state in preparation for a new compilation session. */
- protected void reset() {
- errorCount = warningCount = 0;
- jaxxFiles.clear();
- jaxxFileClassNames.clear();
- symbolTables.clear();
- compilers.clear();
- if (profiler != null) {
- profiler.clear();
- }
- }
-
- public String getVersion() {
- return "2.0.0";
- }
-
- /**
- * Creates a dummy Compiler for use in unit testing.
- *
- * @return the compiler
- */
- public static JAXXCompiler createDummyCompiler() {
- return createDummyCompiler(JAXXCompiler.class.getClassLoader());
- }
-
- /**
- * Creates a dummy Compiler for use in unit testing.
- *
- * @param classLoader class loader to use
- * @return the compiler
- */
- public static JAXXCompiler createDummyCompiler(ClassLoader classLoader) {
- return new JAXXCompiler(classLoader) {
- };
- }
-
- /**
- * @param className the name of the class to use
- * @return the compiler instance which is processing the specified JAXX class. Each class is compiled by a
- * different compiler instance.
- */
- public JAXXCompiler getJAXXCompiler(String className) {
- return compilers != null ? compilers.get(className) : null;
- }
-
- /**
- * @param className the name of the class to use
- * @return the symbol table for the specified JAXX class. Must be called during the second compiler pass.
- * Returns <code>null</code> if no such symbol table could be found.
- */
- public SymbolTable getSymbolTable(String className) {
- JAXXCompiler compiler = getJAXXCompiler(className);
- if (compiler == null) {
- return null;
- }
- return compiler.getSymbolTable();
- }
-
- /**
- * Returns the system line separator string.
- *
- * @return the string used to separate lines
- */
- public String getLineSeparator() {
- return System.getProperty("line.separator", "\n");
- }
-
- /**
- * Compiled a set of files.
- *
- * @return <code>true</code> if compilation succeeds, <code>false</code> otherwise
- */
- public synchronized boolean compile() {
- //reset(); // just to be safe...
- compilerCount = 0;
- jaxxFiles.addAll(Arrays.asList(files));
- jaxxFileClassNames.addAll(Arrays.asList(classNames));
- try {
- boolean success = true;
-
- // pass 1
- if (!nextStep(LifeCycle.compile_first_pass, success)) {
- return false;
- }
- boolean compiled;
- do {
- compiled = false;
- assert jaxxFiles.size() == jaxxFileClassNames.size();
- java.util.Iterator<File> filesIterator = new ArrayList<File>(jaxxFiles).iterator(); // clone it so it can safely be modified while we're iterating
- java.util.Iterator<String> classNamesIterator = new ArrayList<String>(jaxxFileClassNames).iterator();
- while (filesIterator.hasNext()) {
- File file = filesIterator.next();
- String className = classNamesIterator.next();
- if (log.isDebugEnabled()) {
- log.debug("compile first pass for " + className);
- }
- if (symbolTables.get(file) == null) {
- compiled = true;
- if (compilers.containsKey(className)) {
- throw new CompilerException("Internal error: " + className + " is already being compiled, attempting to compile it again");
- }
-
- File destDir = configuration.getTargetDirectory();
- if (destDir != null) {
- int dotPos = className.lastIndexOf(".");
- if (dotPos != -1) {
- destDir = new File(destDir, className.substring(0, dotPos).replace('.', File.separatorChar));
- }
- if (!destDir.exists() && !destDir.mkdirs()) {
- log.warn("could not create directory " + destDir);
- continue;
- }
- } else {
- //destDir = file.getParentFile();
- }
- JAXXCompiler compiler = newCompiler(file.getParentFile(), file, className);
- addProfileTime(compiler, currentPass.name() + "_start");
- compilers.put(className, compiler);
- compiler.compileFirstPass();
- addProfileTime(compiler, currentPass.name() + "_end");
- assert !symbolTables.values().contains(compiler.getSymbolTable()) : "symbolTable is already registered";
- symbolTables.put(file, compiler.getSymbolTable());
- if (compiler.isFailed()) {
- success = false;
- }
- }
- }
-
- } while (compiled);
-
- // pass 2
- if (!nextStep(LifeCycle.compile_second_pass, success)) {
- return false;
- }
-
- assert jaxxFiles.size() == jaxxFileClassNames.size();
- List<File> jaxxFilesClone = new ArrayList<File>(jaxxFiles);
- for (String className : jaxxFileClassNames) {
- JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during second pass");
- addProfileTime(compiler, currentPass.name() + "_start");
- if (log.isDebugEnabled()) {
- log.debug("runInitializers for " + className);
- }
- if (!compiler.isFailed()) {
- compiler.runInitializers();
- }
- if (log.isDebugEnabled()) {
- log.debug("compile second pass for " + className);
- }
- compiler.compileSecondPass();
- addProfileTime(compiler, currentPass.name() + "_end");
- if (log.isDebugEnabled()) {
- log.debug("done with result [" + !compiler.isFailed() + "] for " + className);
- }
- if (compiler.isFailed()) {
- success = false;
- }
- }
- if (!jaxxFilesClone.equals(jaxxFiles)) {
- throw new AssertionError("Internal error: compilation set altered during pass 2 (was " + jaxxFilesClone + ", modified to " + jaxxFiles + ")");
- }
-
- // stylesheet application
- if (!nextStep(LifeCycle.stylesheet_pass, success)) {
- return false;
- }
- assert jaxxFiles.size() == jaxxFileClassNames.size();
- for (String className : jaxxFileClassNames) {
- JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during stylesheet application");
- addProfileTime(compiler, currentPass.name() + "_start");
- compiler.applyStylesheets();
- addProfileTime(compiler, currentPass.name() + "_end");
- if (compiler.isFailed()) {
- success = false;
- }
- }
-
- // code generation
- if (!nextStep(LifeCycle.generate_pass, success)) {
- return false;
- }
- assert jaxxFiles.size() == jaxxFileClassNames.size();
- List<Generator> generators = GeneratorManager.getGenerators();
- for (String className : jaxxFileClassNames) {
- JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during code generation");
- addProfileTime(compiler, currentPass.name() + "_start");
- compiler.generateCode(generators);
- addProfileTime(compiler, currentPass.name() + "_end");
- //compiler.generateCode();
- if (compiler.isFailed()) {
- success = false;
- }
- }
-
- if (configuration.isProfile()) {
- // profile pass (only if succes compile)
- if (!nextStep(LifeCycle.profile_pass, success)) {
- return false;
- }
- StringBuilder buffer = profiler.computeProfileReport();
- log.info(buffer.toString());
- }
-
- return report(success);
-
- //FIXME : deal better the exception treatment...
- } catch (CompilerException e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- return false;
- } catch (Throwable e) {
- e.printStackTrace();
- return false;
- } finally {
- compilerCount = compilers.size();
- //TC - 20081018 only reset when no error was detected
- if (configuration.isResetAfterCompile() && errorCount == 0) {
- reset();
- }
- }
- }
-
- public int getCompilerCount() {
- return compilerCount;
- }
-
- protected JAXXCompiler getCompiler(String className, String message) {
- JAXXCompiler compiler = compilers.get(className);
- if (compiler == null) {
- throw new CompilerException(message);
- }
- return compiler;
- }
-
- protected boolean nextStep(LifeCycle nextCycle, boolean success) {
- if (!success) {
- return report(false);
- }
- currentPass = nextCycle;
- return true;
- }
-
- protected boolean report(boolean success) {
- if (warningCount == 1) {
- System.err.println("1 warning");
- } else if (warningCount > 0) {
- System.err.println(warningCount + " warnings");
- }
- if (errorCount == 1) {
- System.err.println("1 error");
- } else if (errorCount > 0) {
- System.err.println(errorCount + " errors");
- }
- return success;
- }
-
- protected JAXXCompiler newCompiler(File parentFile, File file, String className) throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException {
- Constructor<? extends JAXXCompiler> cons = configuration.getCompilerClass().getConstructor(File.class, File.class, String.class, CompilerConfiguration.class);
- return cons.newInstance(parentFile, file, className, configuration);
- }
-
- public static void addProfileTime(JAXXCompiler compiler, String key) {
- JAXXProfile p = JAXXCompilerLaunchor.get().profiler;
- if (p != null) {
- p.addTime(compiler, key);
- }
- }
-}
Copied: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java (from rev 1582, branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java)
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java (rev 0)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -0,0 +1,558 @@
+package jaxx.compiler;
+
+import jaxx.compiler.generators.Generator;
+import jaxx.compiler.spi.Initializer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.TreeMap;
+import jaxx.compiler.decorators.CompiledObjectDecorator;
+
+/**
+ * @author chemit
+ * @since 2.0.0 was previously JAXXCompilerLaunchor
+ */
+public class JAXXEngine {
+
+ /**
+ * Logger
+ */
+ protected static final Log log = LogFactory.getLog(JAXXEngine.class);
+
+ protected enum LifeCycle {
+
+ init,// state before compilation
+ compile_first_pass, // state when first pass of compilation
+ compile_second_pass, // state when second pass of compilation
+ stylesheet_pass, // state when applygin stylesheet phase after compilation
+ generate_pass, // state when generation phase
+ profile_pass // state when profile
+ }
+ /** shared instance of unique launchor at a givne time. */
+ protected static JAXXEngine singleton;
+
+ /**
+ * Create a new empty launchor and set it as current launchor accessible via method {@link #get()}
+ *
+ * @return the new instanciated launchor
+ */
+ public static synchronized JAXXEngine newLaunchor() {
+ return newLaunchor((File[]) null, null, null);
+ }
+
+ /**
+ * Create a new launchor and set it as current launchor accessible via method {@link #get()}.
+ * <p/>
+ * The launchor will be prepared to compile a set of files, expressed as paths relative to a base directory.
+ * The class names of the compiled files are derived from the relative path strings
+ * (e.g. "example/Foo.jaxx" compiles into a class named "example.Foo").
+ *
+ * @param base the directory against which to resolve relative paths
+ * @param relativePaths a list of relative paths to .jaxx files being compiled
+ * @param configuration the compiler configuration to use
+ * @return the new instanciated launchor
+ */
+ public static synchronized JAXXEngine newLaunchor(File base, String[] relativePaths, CompilerConfiguration configuration) {
+ File[] files = new File[relativePaths.length];
+ String[] classNames = new String[relativePaths.length];
+ for (int i = 0; i < files.length; i++) {
+ files[i] = new File(base, relativePaths[i]);
+ classNames[i] = relativePaths[i].substring(0, relativePaths[i].lastIndexOf("."));
+ classNames[i] = classNames[i].replace(File.separatorChar, '.');
+ classNames[i] = classNames[i].replace('/', '.');
+ classNames[i] = classNames[i].replace('\\', '.');
+ classNames[i] = classNames[i].replace(':', '.');
+ }
+ return newLaunchor(files, classNames, configuration);
+ }
+
+ /**
+ * Create a new launchor and set it as current launchor accessible via method {@link #get()}.
+ * <p/>
+ * The launchor will be prepared to compile a set of files, with the class names specified explicitly.
+ * The class compiled from files[i] will be named classNames[i].
+ *
+ * @param files the .jaxx files to compile
+ * @param classNames the names of the classes being compiled
+ * @param configuration the compiler configuration to use
+ * @return the new instanciated launchor
+ */
+ public static synchronized JAXXEngine newLaunchor(File[] files, String[] classNames, CompilerConfiguration configuration) {
+ if (singleton != null) {
+ singleton.reset();
+ }
+ singleton = new JAXXEngine(files, classNames, configuration);
+ return singleton;
+ }
+
+ /**
+ * @return the current launchor
+ * @throws NullPointerException if no launchor was registred via a <code>newLaunchor-like</code> method.
+ */
+ public static JAXXEngine get() throws NullPointerException {
+ if (singleton == null) {
+ throw new NullPointerException("no launchor was registred via newLaunchor method");
+ }
+ return singleton;
+ }
+
+ /** @return <code> if there is a launchor registred, <code>false</code> otherwise. */
+ public static boolean isRegistred() {
+ return singleton != null;
+ }
+
+ /**
+ * Load the {@link Initializer} services found via the{@link ServiceLoader} mecanism.
+ *
+ * @param verbose <ocde>true</code> to print initializers
+ */
+ public static void loadLibraries(boolean verbose) {
+ //BeanInfoUtil.reset();
+ ClassLoader classloader = Thread.currentThread().getContextClassLoader();
+ if (verbose) {
+ log.info("with cl " + classloader);
+ }
+ ServiceLoader<Initializer> loader = ServiceLoader.load(Initializer.class, classloader);
+ for (Initializer initializer : loader) {
+ if (verbose) {
+ log.info("load initializer " + initializer);
+ }
+ initializer.initialize();
+ }
+ }
+ /**
+ * configuration of the launchor and underlines compilers
+ */
+ protected CompilerConfiguration configuration;
+ /**
+ * original list of files to compile
+ */
+ protected final File[] files;
+ /**
+ * original list of classes to compile
+ */
+ protected final String[] classNames;
+ /**
+ * Files to be treated while compilation.
+ */
+ protected List<File> jaxxFiles = new ArrayList<File>();
+ /**
+ * Class names corresponding to the files in the jaxxFiles list.
+ */
+ protected List<String> jaxxFileClassNames = new ArrayList<String>();
+ /**
+ * Maps the names of classes being compiled to the compiler instance handling the compilation.
+ */
+ protected Map<String, JAXXCompiler> compilers = new HashMap<String, JAXXCompiler>();
+ /**
+ * Maps the names of classes being compiled to their symbol tables (created after the first compiler pass).
+ */
+ protected Map<File, SymbolTable> symbolTables = new HashMap<File, SymbolTable>();
+ /**
+ *
+ */
+ protected LifeCycle currentPass;
+ /**
+ *
+ */
+ protected int errorCount;
+ /**
+ *
+ */
+ protected int warningCount;
+ /**
+ * number of registred compiler
+ */
+ protected int compilerCount;
+ /**
+ * profile attached to the engine (can be null)
+ */
+ protected JAXXProfile profiler;
+ /**
+ * decorators available in engine
+ */
+ protected Map<String, CompiledObjectDecorator> decorators;
+ /**
+ * generators available in engine
+ */
+ protected List<Generator> generators;
+
+ protected JAXXEngine(File[] files, String[] classNames, CompilerConfiguration options) {
+ this.configuration = options == null ? new DefaultCompilerConfiguration() : options;
+ this.files = files;
+ this.classNames = classNames;
+ if (this.configuration.isVerbose()) {
+ log.info("files : " + Arrays.toString(files));
+ }
+ if (this.configuration.isProfile()) {
+ profiler = new JAXXProfile();
+ }
+ }
+
+ public void init() {
+ compilerCount = 0;
+ jaxxFiles.addAll(Arrays.asList(files));
+ jaxxFileClassNames.addAll(Arrays.asList(classNames));
+ }
+
+ /** Resets all state in preparation for a new compilation session. */
+ protected void reset() {
+ errorCount = warningCount = 0;
+ jaxxFiles.clear();
+ jaxxFileClassNames.clear();
+ symbolTables.clear();
+ compilers.clear();
+ if (profiler != null) {
+ profiler.clear();
+ profiler = null;
+ }
+ if (decorators != null) {
+ decorators.clear();
+ decorators = null;
+ }
+ if (generators != null) {
+ generators.clear();
+ generators = null;
+ }
+ }
+
+ public String getVersion() {
+ return "2.0.0";
+ }
+
+// /**
+// * Creates a dummy Compiler for use in unit testing.
+// *
+// * @return the compiler
+// */
+// public static JAXXCompiler createDummyCompiler() {
+// return createDummyCompiler(JAXXCompiler.class.getClassLoader());
+// }
+ /**
+ * Creates a dummy Compiler for use in unit testing.
+ *
+ * @param classLoader class loader to use
+ * @return the compiler
+ */
+ public static JAXXCompiler createDummyCompiler(final ClassLoader classLoader) {
+ JAXXCompiler compiler = new JAXXCompiler(null, null, null, null, null, null);
+ compiler.classLoader = classLoader;
+ return compiler;
+ }
+
+ /**
+ * @param className the name of the class to use
+ * @return the compiler instance which is processing the specified JAXX class. Each class is compiled by a
+ * different compiler instance.
+ */
+ public JAXXCompiler getJAXXCompiler(String className) {
+ return compilers == null ? null : compilers.get(className);
+ }
+
+ /**
+ * @param className the name of the class to use
+ * @return the symbol table for the specified JAXX class. Must be called during the second compiler pass.
+ * Returns <code>null</code> if no such symbol table could be found.
+ */
+ public SymbolTable getSymbolTable(String className) {
+ JAXXCompiler compiler = getJAXXCompiler(className);
+ if (compiler == null) {
+ return null;
+ }
+ return compiler.getSymbolTable();
+ }
+
+ /**
+ * Returns the system line separator string.
+ *
+ * @return the string used to separate lines
+ */
+ public String getLineSeparator() {
+ return System.getProperty("line.separator", "\n");
+ }
+
+ public CompiledObjectDecorator getDecorator(String name) {
+ CompiledObjectDecorator decorator = getDecorators().get(name);
+ if (decorator == null) {
+ throw new IllegalArgumentException("could not find decorator with key " + name + " (known decorators : " + getDecorators().keySet());
+ }
+ return decorator;
+ }
+
+ public CompiledObjectDecorator getDecorator(Class<?> type) {
+ for (CompiledObjectDecorator decorator : getDecorators().values()) {
+ if (type == decorator.getClass()) {
+ return decorator;
+ }
+ }
+ return null;
+ }
+
+ protected synchronized Map<String, CompiledObjectDecorator> getDecorators() {
+ if (decorators == null) {
+ decorators = new TreeMap<String, CompiledObjectDecorator>();
+ // load decorators
+ ServiceLoader<CompiledObjectDecorator> loader = ServiceLoader.load(CompiledObjectDecorator.class);
+ for (CompiledObjectDecorator c : loader) {
+ decorators.put(c.getName(), c);
+ }
+ }
+ return decorators;
+ }
+
+ public List<Generator> getGenerators() {
+ if (generators == null) {
+ generators = new ArrayList<Generator>();
+ for (Generator generator : ServiceLoader.load(Generator.class)) {
+ generators.add(generator);
+ }
+ }
+ return generators;
+ }
+
+ /**
+ * Compiled a set of files.
+ *
+ * @return <code>true</code> if compilation succeeds, <code>false</code> otherwise
+ */
+ public synchronized boolean compile() {
+
+ init();
+ try {
+ boolean success = true;
+
+ // pass 1
+ if (!nextStep(LifeCycle.compile_first_pass, success)) {
+ return false;
+ }
+ success = firstPass();
+
+ // pass 2
+ if (!nextStep(LifeCycle.compile_second_pass, success)) {
+ return false;
+ }
+ assert jaxxFiles.size() == jaxxFileClassNames.size();
+ success = secondPass();
+
+ // stylesheet application
+ if (!nextStep(LifeCycle.stylesheet_pass, success)) {
+ return false;
+ }
+ assert jaxxFiles.size() == jaxxFileClassNames.size();
+ success = applyCss();
+
+ // code generation
+ if (!nextStep(LifeCycle.generate_pass, success)) {
+ return false;
+ }
+ assert jaxxFiles.size() == jaxxFileClassNames.size();
+ success = generate();
+
+ if (configuration.isProfile()) {
+ // profile pass (only if succes compile)
+ if (!nextStep(LifeCycle.profile_pass, success)) {
+ return false;
+ }
+ StringBuilder buffer = profiler.computeProfileReport();
+ log.info(buffer.toString());
+ }
+
+ return report(success);
+
+ //FIXME : deal better the exception treatment...
+ } catch (CompilerException e) {
+ System.err.println(e.getMessage());
+ e.printStackTrace();
+ return false;
+ } catch (Throwable e) {
+ e.printStackTrace();
+ return false;
+ } finally {
+ compilerCount = compilers.size();
+ //TC - 20081018 only reset when no error was detected
+ if (configuration.isResetAfterCompile() && errorCount == 0) {
+ reset();
+ }
+ }
+ }
+
+ protected boolean firstPass() throws Exception {
+ boolean success = true;
+ boolean compiled;
+ do {
+ compiled = false;
+ assert jaxxFiles.size() == jaxxFileClassNames.size();
+ java.util.Iterator<File> filesIterator = new ArrayList<File>(jaxxFiles).iterator(); // clone it so it can safely be modified while we're iterating
+ java.util.Iterator<String> classNamesIterator = new ArrayList<String>(jaxxFileClassNames).iterator();
+ while (filesIterator.hasNext()) {
+ File file = filesIterator.next();
+ String className = classNamesIterator.next();
+ if (log.isDebugEnabled()) {
+ log.debug("compile first pass for " + className);
+ }
+ if (symbolTables.get(file) == null) {
+ compiled = true;
+ if (compilers.containsKey(className)) {
+ throw new CompilerException("Internal error: " + className + " is already being compiled, attempting to compile it again");
+ }
+
+ File destDir = configuration.getTargetDirectory();
+ if (destDir != null) {
+ int dotPos = className.lastIndexOf(".");
+ if (dotPos != -1) {
+ destDir = new File(destDir, className.substring(0, dotPos).replace('.', File.separatorChar));
+ }
+ if (!destDir.exists() && !destDir.mkdirs()) {
+ log.warn("could not create directory " + destDir);
+ continue;
+ }
+ } else {
+ //destDir = file.getParentFile();
+ }
+ JAXXCompiler compiler = newCompiler(file.getParentFile(), file, className);
+ addProfileTime(compiler, currentPass.name() + "_start");
+ compilers.put(className, compiler);
+ compiler.compileFirstPass();
+ addProfileTime(compiler, currentPass.name() + "_end");
+ assert !symbolTables.values().contains(compiler.getSymbolTable()) : "symbolTable is already registered";
+ symbolTables.put(file, compiler.getSymbolTable());
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
+ }
+
+ } while (compiled);
+ return success;
+ }
+
+ protected boolean secondPass() throws Exception {
+ boolean success = true;
+ List<File> jaxxFilesClone = new ArrayList<File>(jaxxFiles);
+ for (String className : jaxxFileClassNames) {
+ JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during second pass");
+ addProfileTime(compiler, currentPass.name() + "_start");
+ if (log.isDebugEnabled()) {
+ log.debug("runInitializers for " + className);
+ }
+ if (!compiler.isFailed()) {
+ compiler.runInitializers();
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("compile second pass for " + className);
+ }
+ compiler.compileSecondPass();
+ addProfileTime(compiler, currentPass.name() + "_end");
+ if (log.isDebugEnabled()) {
+ log.debug("done with result [" + !compiler.isFailed() + "] for " + className);
+ }
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
+ if (!jaxxFilesClone.equals(jaxxFiles)) {
+ throw new AssertionError("Internal error: compilation set altered during pass 2 (was " + jaxxFilesClone + ", modified to " + jaxxFiles + ")");
+ }
+ return success;
+ }
+
+ protected boolean applyCss() throws Exception {
+ boolean success = true;
+
+ for (String className : jaxxFileClassNames) {
+ JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during stylesheet application");
+ addProfileTime(compiler, currentPass.name() + "_start");
+ compiler.applyStylesheets();
+ addProfileTime(compiler, currentPass.name() + "_end");
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
+ return success;
+ }
+
+ protected boolean generate() throws Exception {
+ boolean success = true;
+ List<Generator> gens = getGenerators();
+ for (String className : jaxxFileClassNames) {
+ JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during code generation");
+ addProfileTime(compiler, currentPass.name() + "_start");
+ compiler.generateCode(gens);
+ addProfileTime(compiler, currentPass.name() + "_end");
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
+ return success;
+ }
+
+ public int getCompilerCount() {
+ return compilerCount;
+ }
+
+ protected JAXXCompiler getCompiler(String className, String message) {
+ JAXXCompiler compiler = compilers.get(className);
+ if (compiler == null) {
+ throw new CompilerException(message);
+ }
+ return compiler;
+ }
+
+ protected boolean nextStep(LifeCycle nextCycle, boolean success) {
+ if (!success) {
+ return report(false);
+ }
+ currentPass = nextCycle;
+ return true;
+ }
+
+ protected boolean report(boolean success) {
+ if (warningCount == 1) {
+ System.err.println("1 warning");
+ } else if (warningCount > 0) {
+ System.err.println(warningCount + " warnings");
+ }
+ if (errorCount == 1) {
+ System.err.println("1 error");
+ } else if (errorCount > 0) {
+ System.err.println(errorCount + " errors");
+ }
+ return success;
+ }
+
+ protected JAXXCompiler newCompiler(File parentFile, File file, String className) throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException {
+ Constructor<? extends JAXXCompiler> cons = configuration.getCompilerClass().getConstructor(JAXXEngine.class, File.class, File.class, String.class, CompilerConfiguration.class, List.class);
+ return cons.newInstance(this, parentFile, file, className, configuration, Arrays.asList(new String[]{
+ "java.awt.*",
+ "java.awt.event.*",
+ "java.beans.*",
+ "java.io.*",
+ "java.lang.*",
+ "java.util.*",
+ "javax.swing.*",
+ "javax.swing.border.*",
+ "javax.swing.event.*",
+ "jaxx.runtime.swing.JAXXButtonGroup",
+ "jaxx.runtime.swing.HBox",
+ "jaxx.runtime.swing.VBox",
+ "jaxx.runtime.swing.Table",
+ "static org.nuiton.i18n.I18n._",
+ "static jaxx.runtime.Util.createImageIcon"
+ }));
+ }
+
+ public void addProfileTime(JAXXCompiler compiler, String key) {
+ if (profiler != null) {
+ profiler.addTime(compiler, key);
+ }
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
___________________________________________________________________
Added: svn:mergeinfo
+
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXProfile.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXProfile.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JAXXProfile.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -5,7 +5,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap;
-import jaxx.compiler.JAXXCompilerLaunchor.LifeCycle;
+import jaxx.compiler.JAXXEngine.LifeCycle;
import org.nuiton.util.StringUtil;
/**
Deleted: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaArgument.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaArgument.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaArgument.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,81 +0,0 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
-package jaxx.compiler;
-
-/**
- * Represents an argument to a <code>JavaMethod</code>.
- *
- * @see JavaMethod
- */
-public class JavaArgument {
-
- private String name;
- private String type;
- private boolean isFinal;
-
- /**
- * Creates a new <code>JavaArgument</code> with the specified name and type. For example, the method <code>main()</code>
- * might have a <code>JavaArgument</code> with a name of <code>"arg"</code> and a type of <code>"java.lang.String[]"</code>.
- *
- * @param type the argument's type, as it would appear in Java source code
- * @param name the argument's name
- */
- public JavaArgument(String type, String name) {
- this(type, name, false);
- }
-
- /**
- * Creates a new <code>JavaArgument</code> with the specified name, type, and finality. For example, the method <code>main()</code>
- * might have a <code>JavaArgument</code> with a name of <code>"arg"</code> and a type of <code>"java.lang.String[]"</code>. The
- * <code>isFinal</code> parameter allows the presence of the <code>final</code> keyword on the argument to be controlled.
- *
- * @param type the argument's type, as it would appear in Java source code
- * @param name the argument's name
- * @param isFinal <code>true</code> if the argument should be marked final
- */
- public JavaArgument(String type, String name, boolean isFinal) {
- this.type = type;
- this.name = name;
- this.isFinal = isFinal;
- }
-
- /**
- * Returns the argument's name.
- *
- * @return the name of the argument
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the argument's type as it would be represented in Java source code.
- *
- * @return the argument's type
- */
- public String getType() {
- return type;
- }
-
- /**
- * Returns <code>true</code> if the <code>final</code> keyword should appear before the argument.
- *
- * @return <code>true</code> if the argument is final
- */
- public boolean isFinal() {
- return isFinal;
- }
-
- /**
- * Returns the Java source code for this argument.
- *
- * @return the Java source code for this argument
- */
- @Override
- public String toString() {
- String result = type + ' ' + name;
- return isFinal ? "final " + result : result;
- }
-}
Deleted: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaField.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaField.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaField.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,182 +0,0 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
-package jaxx.compiler;
-
-import java.lang.reflect.Modifier;
-import java.util.Comparator;
-
-/**
- * Represents a field in a Java source file being generated for output. <code>JavaFields</code> are created
- * and added to a {@link JavaFile}, which can then output Java source code.
- */
-public class JavaField implements Comparable<JavaField> {
-
- private int modifiers;
- private String type;
- private String name;
- private String initializer;
-
- /**
- * Constructs a new <code>JavaField</code>. The <code>modifiers</code> parameter is a bit mask of the
- * constants from {@link java.lang.reflect.Modifier}, and the <code>type</code> of the field should be
- * represented as it would appear in Java source code.
- *
- * @param modifiers the modifier keywords that should appear as part of the field's declaration
- * @param type the type of the field as it would appear in Java source code
- * @param name the field's name
- */
- public JavaField(int modifiers, String type, String name) {
- this(modifiers, type, name, null);
- }
-
- /**
- * Constructs a new <code>JavaField</code>. The <code>modifiers</code> parameter is a bit mask of the
- * constants from <code>java.lang.reflect.Modifier</code>, and the <code>type</code> of the field should be
- * represented as it would appear in Java source code. The <code>initializer</code> is the initial
- * value of the field as it would appear in Java source code, or <code>null</code> to leave it at the
- * default value.
- *
- * @param modifiers the modifier keywords that should appear as part of the field's declaration
- * @param type the type of the field as it would appear in Java source code
- * @param name the field's name
- * @param initializer the initial value of the field, as it would appear in Java source code
- */
- public JavaField(int modifiers, String type, String name, String initializer) {
- this.modifiers = modifiers;
- this.type = type;
- this.name = name;
- this.initializer = initializer;
- }
-
- /**
- * Returns a bit mask describing the modifier keywords which should appear as part of this field's
- * declaration. See <code>java.lang.reflect.Modifier</code> for more information on decoding this
- * field.
- *
- * @return the modifier bit mask
- */
- public int getModifiers() {
- return modifiers;
- }
-
- /**
- * Returns the field's name.
- *
- * @return the field's name
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the field's type, as it would be represented in Java source code.
- *
- * @return the field's type
- */
- public String getType() {
- return type;
- }
-
- /**
- * Returns the Java source code for this field.
- *
- * @param lineSeparator line separator
- * @return the Java source code for this field
- */
- public String toString(String lineSeparator) {
- StringBuffer result = new StringBuffer();
- result.append(JavaFile.getModifiersText(modifiers));
- result.append(type).append(' ').append(name);
- if (initializer != null) {
- result.append(" = ").append(initializer);
- }
- result.append(';').append(lineSeparator);
- return result.toString();
- }
-
- @Override
- public int compareTo(JavaField o) {
- return COMPARATOR.compare(this, o);
- }
- public static final Comparator<JavaField> COMPARATOR = new Comparator<JavaField>() {
-
- @Override
- public int compare(JavaField o1, JavaField o2) {
-
- int result;
- if ((result = compareStatic(o1, o2)) != 0) {
- return result;
- }
-
- // data sources must be on the last after all other fields
- if ((result = compareDataSource(o1, o2)) != 0) {
- return result;
- }
-
- // same static
- if ((result = compareVisibility(o1, o2)) != 0) {
- return result;
- }
- // same visibility, test name
- return o1.name.compareTo(o2.name);
- }
-
- public int compareStatic(JavaField o1, JavaField o2) {
- // first comparator modifiers : static always before none static
- if (Modifier.isStatic(o1.modifiers) && !Modifier.isStatic(o2.modifiers)) {
- return -1;
- }
- if (!Modifier.isStatic(o1.modifiers) && Modifier.isStatic(o2.modifiers)) {
- return 1;
- }
- return 0;
- }
-
- public int compareDataSource(JavaField o1, JavaField o2) {
- // first comparator modifiers : static always before none static
- if (o1.name.startsWith("$DataSource") && !o2.name.startsWith("$DataSource")) {
- return 1;
- }
- if (!o1.name.startsWith("$DataSource") && o2.name.startsWith("$DataSource")) {
- return -1;
- }
- return 0;
- }
-
- public int compareVisibility(JavaField o1, JavaField o2) {
- // first comparator modifiers : static always before none static
- if (!Modifier.isPublic(o1.modifiers) && Modifier.isPublic(o2.modifiers)) {
- return 1;
- }
-
- if (Modifier.isPublic(o1.modifiers) && !Modifier.isPublic(o2.modifiers)) {
- return -1;
- }
-
- if (Modifier.isProtected(o1.modifiers) && !Modifier.isProtected(o2.modifiers)) {
- return -1;
- }
- if (!Modifier.isProtected(o1.modifiers) && Modifier.isProtected(o2.modifiers)) {
- return 1;
- }
-
- if (Modifier.isPrivate(o1.modifiers) && !Modifier.isPrivate(o2.modifiers)) {
- return -1;
- }
- if (!Modifier.isPrivate(o1.modifiers) && Modifier.isPrivate(o2.modifiers)) {
- return 1;
- }
- return 0;
- }
- };
-
- public static JavaField newField(int modifiers, String returnType, String name) {
- return newField(modifiers, returnType, name, null);
- }
-
- public static JavaField newField(int modifiers, String returnType, String name, String initializer) {
- return new JavaField(modifiers, returnType, name, initializer);
- }
-}
Deleted: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaFile.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaFile.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaFile.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,317 +0,0 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
-package jaxx.compiler;
-
-import jaxx.compiler.JavaMethod.MethodOrder;
-
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map.Entry;
-
-/**
- * A Java source file being generated for output. Once the class is completely initialized, use the
- * {@link #toString} method to generate source code for it.
- */
-public class JavaFile {
-
- protected static final String GETTER_PATTERN = "return %1$s;";
- protected static final String BOOLEAN_GETTER_PATTERN = "return %1$s !=null && %1$s;";
- protected static final String SETTER_PATTERN = "%1$s oldValue = this.%2$s;\nthis.%2$s = newValue;\nfirePropertyChange(\"%2$s\", oldValue, newValue);";
- private int modifiers;
- private String className;
- private List<String> imports = new ArrayList<String>();
- private List<JavaField> fields = new ArrayList<JavaField>();
- private List<JavaMethod> methods = new ArrayList<JavaMethod>();
- private List<JavaFile> innerClasses = new ArrayList<JavaFile>();
- private String superClass;
- private List<String> interfaces;
- private StringBuffer rawBodyCode = new StringBuffer();
- private boolean superclassIsJAXXObject;
- private boolean abstractClass;
- private String genericType;
- private String superGenericType;
-
- public JavaFile() {
- }
-
- public JavaFile(int modifiers, String className, String superClass) {
- this(modifiers, className, superClass, null);
- }
-
- public JavaFile(int modifiers, String className, String superClass, List<String> interfaces) {
- this.modifiers = modifiers;
- this.className = className;
- this.superClass = superClass;
- this.interfaces = interfaces;
- }
-
- public void addImport(String importString) {
- imports.add(importString);
- }
-
- public void addImport(Class<?> importString) {
- imports.add(importString.getName());
- }
-
- public String[] getImports() {
- return imports.toArray(new String[imports.size()]);
- }
-
- public int getModifiers() {
- return modifiers;
- }
-
- public void setModifiers(int modifiers) {
- this.modifiers = modifiers;
- }
-
- public String getClassName() {
- return className;
- }
-
- public void setClassName(String className) {
- this.className = className;
- }
-
- public String getSuperClass() {
- return superClass;
- }
-
- public void setSuperClass(String superClass) {
- this.superClass = superClass;
- }
-
- public List<String> getInterfaces() {
- if (interfaces == null) {
- interfaces = new ArrayList<String>();
- }
- return interfaces;
- }
-
- public void setInterfaces(List<String> interfaces) {
- this.interfaces = interfaces;
- }
-
- public void setGenericType(String genericType) {
- this.genericType = genericType;
- }
-
- public void addMethod(JavaMethod method) {
- methods.add(method);
- }
-
- public JavaMethod[] getMethods() {
- return methods.toArray(new JavaMethod[methods.size()]);
- }
-
- public void addField(JavaField field) {
- addField(field, false);
- }
-
- public void addField(JavaField field, boolean javaBean) {
- addSimpleField(field);
- String id = field.getName();
- String capitalizedName = org.apache.commons.lang.StringUtils.capitalize(id);
- // add getter file
- String content = String.format(GETTER_PATTERN, id);
- addMethod(new JavaMethod(
- Modifier.isProtected(field.getModifiers()) ? Modifier.PUBLIC : Modifier.PROTECTED,
- field.getType(), "get" + capitalizedName, null, null, content));
-
- if (javaBean) {
- // add full javabean support
- if (Boolean.class.getName().equals(field.getType())) {
- content = String.format(BOOLEAN_GETTER_PATTERN, id);
- addMethod(new JavaMethod(Modifier.PUBLIC, field.getType(), "is" + capitalizedName, null, null, content));
- }
- content = String.format(SETTER_PATTERN, field.getType(), id);
- JavaArgument arg = new JavaArgument(field.getType(), "newValue");
- addMethod(new JavaMethod(Modifier.PUBLIC, "void", "set" + capitalizedName, new JavaArgument[]{arg}, null, content));
- }
- }
-
- public void addSimpleField(JavaField field) {
- fields.add(field);
- }
-
- public JavaField[] getFields() {
- return fields.toArray(new JavaField[fields.size()]);
- }
-
- public static String addIndentation(String source, int indentation, String lineSeparator) {
- return indent(source, indentation, false, lineSeparator);
- }
-
- public static String setIndentation(String source, int indentation, String lineSeparator) {
- return indent(source, indentation, true, lineSeparator);
- }
-
- public static String indent(String source, int indentation, boolean trim, String lineSeparator) {
- if (trim) {
- source = source.trim();
- }
- char[] spaces = new char[indentation];
- Arrays.fill(spaces, ' ');
- StringBuffer result = new StringBuffer();
- String[] lines = source.split(System.getProperty("line.separator") + "|\n");
- for (int i = 0; i < lines.length; i++) {
- if (i > 0) {
- result.append(lineSeparator);
- }
- result.append(spaces);
- result.append(trim ? lines[i].trim() : lines[i]);
- }
- return result.toString();
- }
-
- public void addBodyCode(String bodyCode) {
- rawBodyCode.append(bodyCode);
- }
-
- public String getClassBody(String lineSeparator) {
- StringBuffer result = new StringBuffer();
- if (fields.size() > 0) {
- java.util.Collections.sort(fields); // sort fields
-
- for (JavaField field : fields) {
- result.append(addIndentation(field.toString(lineSeparator), 4, lineSeparator));
- result.append(lineSeparator);
- }
-
- result.append(lineSeparator);
- }
-
- if (rawBodyCode.length() > 0) {
- result.append(addIndentation("/* begin raw body code */\n", 4, lineSeparator));
- String s = rawBodyCode.toString();
- if (!s.startsWith(lineSeparator)) {
- result.append(lineSeparator);
- }
- result.append(addIndentation(s, 4, lineSeparator));
- result.append(lineSeparator);
- result.append(addIndentation("/* end raw body code */", 4, lineSeparator));
- result.append(lineSeparator);
- }
-
- for (JavaFile innerClass : innerClasses) {
- result.append(addIndentation(innerClass.toString(), 4, lineSeparator));
- result.append(lineSeparator).append(lineSeparator);
- }
-
- EnumMap<MethodOrder, List<JavaMethod>> map = JavaMethod.getSortedMethods(methods);
- for (Entry<MethodOrder, List<JavaMethod>> entry : map.entrySet()) {
- List<JavaMethod> list = entry.getValue();
- entry.getKey().generate(result, list, lineSeparator);
- list.clear();
- }
- map.clear();
-
- return result.toString();
- }
-
- public String getClassDefinition(String lineSeparator) {
- StringBuffer result = new StringBuffer();
- result.append(getModifiersText(modifiers));
- if (abstractClass) {
- result.append("abstract ");
- }
- result.append("class ");
- result.append(className.substring(className.lastIndexOf(".") + 1));
- if (genericType != null) {
- result.append('<').append(genericType).append('>');
- }
- result.append(" extends ");
- result.append(superClass);
- if (superGenericType != null) {
- result.append('<').append(superGenericType).append('>');
- }
- if (interfaces != null && !interfaces.isEmpty()) {
- result.append(" implements ").append(interfaces.get(0));
- for (int i = 1; i < interfaces.size(); i++) {
- /*if (i > 0) {
- result.append(", ");
- }*/
- result.append(", ").append(interfaces.get(i));
- }
- }
- result.append(" {");
- result.append(lineSeparator);
- result.append(getClassBody(lineSeparator));
- result.append("}");
- return result.toString();
- }
-
- public static String getModifiersText(int modifiers) {
- if (modifiers == 0) {
- return "";
- } else {
- return Modifier.toString(modifiers) + ' ';
- }
- }
-
- /**
- * Returns the Java source code for this class.
- *
- * @param lineSeparator line separator
- * @return a complete Java file for this class
- */
- public String toString(String lineSeparator) {
- StringBuffer result = new StringBuffer();
- if (className.indexOf(".") != -1) {
- result.append("package ").append(className.substring(0, className.lastIndexOf("."))).append(";");
- result.append(lineSeparator);
- result.append(lineSeparator);
- }
-
- if (imports.size() > 0) {
- for (String anImport : imports) {
- result.append("import ");
- result.append(anImport);
- result.append(';');
- result.append(lineSeparator);
- }
- result.append(lineSeparator);
- }
-
- result.append(getClassDefinition(lineSeparator));
- return result.toString();
- }
-
- public void addInterface(String canonicalName) {
- if (interfaces == null || !interfaces.contains(canonicalName)) {
- getInterfaces().add(canonicalName);
- }
- }
-
- public void addInterfaces(String[] canonicalNames) {
- if (canonicalNames == null) {
- return;
- }
- for (String canonicalName : canonicalNames) {
- if (interfaces == null || !interfaces.contains(canonicalName)) {
- getInterfaces().add(canonicalName);
- }
- }
- }
-
- public boolean isSuperclassIsJAXXObject() {
- return superclassIsJAXXObject;
- }
-
- public void setSuperclassIsJAXXObject(boolean superclassIsJAXXObject) {
- this.superclassIsJAXXObject = superclassIsJAXXObject;
- }
-
- public void setAbstractClass(boolean abstractClass) {
- this.abstractClass = abstractClass;
- }
-
- public void setSuperGenericType(String superGenericType) {
- this.superGenericType = superGenericType;
- }
-}
Deleted: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaMethod.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaMethod.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaMethod.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,493 +0,0 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
-package jaxx.compiler;
-
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.EnumMap;
-import java.util.EnumSet;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Represents a method in a Java source file being generated for output. <code>JavaMethods</code> are created
- * and added to a {@link JavaFile}, which can then output Java source code. In addition to normal methods, a
- * <code>JavaMethod</code> can represent a constructor -- constructors should be named after their containing
- * classes and have a return type of <code>null</code>.
- */
-public class JavaMethod implements Comparable<JavaMethod> {
-
- private int modifiers;
- private String returnType;
- private String name;
- private JavaArgument[] arguments;
- private String[] exceptions;
- private StringBuffer bodyCode;
-
- /**
- * Constructs a new no-argument <code>JavaMethod</code> which throws no checked exceptions. The
- * <code>modifiers</code> parameter is a bit mask of the constants from {@link java.lang.reflect.Modifier},
- * and the <code>returnType</code> of the method should be represented as it would appear in Java source
- * code (<code>null</code> for a constructor). The method body is initially empty.
- *
- * @param modifiers the modifier keywords that should appear as part of the method's declaration
- * @param returnType the return type of the method as it would appear in Java source code
- * @param name the method's name
- * @see #appendBodyCode
- */
- //public JavaMethod(int modifiers, String returnType, String name) {
- // this(modifiers, returnType, name, null);
- //}
- /**
- * Constructs a new <code>JavaMethod</code> which throws no checked exceptions. The <code>modifiers</code>
- * parameter is a bit mask of the constants from {@link java.lang.reflect.Modifier}, and the
- * <code>returnType</code> of the method should be represented as it would appear in Java source code
- * (<code>null</code> for a constructor). The method body is initially empty.
- *
- * @param modifiers the modifier keywords that should appear as part of the method's declaration
- * @param returnType the return type of the method as it would appear in Java source code
- * @param name the method's name
- * @param arguments the method's arguments
- * @see #appendBodyCode
- */
- //public JavaMethod(int modifiers, String returnType, String name, JavaArgument[] arguments) {
- // this(modifiers, returnType, name, arguments, null);
- //}
- /**
- * Constructs a new <code>JavaMethod</code>. The <code>modifiers</code> parameter is a bit mask of the
- * constants from {@link java.lang.reflect.Modifier}, and the <code>returnType</code> and <code>exceptions</code>
- * of the method should be represented as they would appear in Java source code (<code>null</code> for a
- * constructor). The method body is initially empty.
- *
- * @param modifiers the modifier keywords that should appear as part of the method's declaration
- * @param returnType the return type of the method as it would appear in Java source code
- * @param name the method's name
- * @param arguments the method's arguments
- * @param exceptions a list of exceptions the methods can throw, as they would be represented in Java source code
- * @see #appendBodyCode
- */
- //public JavaMethod(int modifiers, String returnType, String name, JavaArgument[] arguments, String[] exceptions) {
- // this(modifiers, returnType, name, arguments, exceptions, null);
- //}
- /**
- * Constructs a new <code>JavaMethod</code> containing the specified body code. The <code>modifiers</code> parameter
- * is a bit mask of the constants from {@link java.lang.reflect.Modifier}, and the <code>returnType</code> and
- * <code>exceptions</code> of the method should be represented as they would appear in Java source code (<code>null</code>
- * for a constructor). The method body is initially empty.
- *
- * @param modifiers the modifier keywords that should appear as part of the method's declaration
- * @param returnType the return type of the method as it would appear in Java source code
- * @param name the method's name
- * @param arguments the method's arguments
- * @param exceptions a list of exceptions the methods can throw, as they would be represented in Java source code
- * @param bodyCode Java source code which should appear in the method body
- */
- public JavaMethod(int modifiers, String returnType, String name, JavaArgument[] arguments, String[] exceptions, String bodyCode) {
- this.modifiers = modifiers;
- this.returnType = returnType;
- this.name = name;
- this.arguments = arguments;
- this.exceptions = exceptions;
- this.bodyCode = new StringBuffer(bodyCode != null ? bodyCode : "");
- }
-
- /**
- * Returns a bit mask describing the modifier keywords which should appear as part of this method's
- * declaration. See <code>java.lang.reflect.Modifier</code> for more information on decoding this
- * field.
- *
- * @return the modifier bit mask
- */
- public int getModifiers() {
- return modifiers;
- }
-
- /**
- * Returns the method's return type, as it would be represented in Java source code.
- *
- * @return the method's return type
- */
- public String getReturnType() {
- return returnType;
- }
-
- /**
- * Returns the method's name.
- *
- * @return the method's name
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns a list of the method's arguments.
- *
- * @return the method's arguments
- */
- public JavaArgument[] getArguments() {
- return arguments;
- }
-
- /**
- * Returns a list of exceptions the method can throw.
- *
- * @return the method's exceptions
- */
- public String[] getExceptions() {
- return exceptions;
- }
-
- /**
- * Returns the Java source code for the method's body.
- *
- * @return the method's body code
- */
- public String getBodyCode() {
- return bodyCode.toString();
- }
-
- /**
- * Appends additional code to the method's body.
- *
- * @param extraCode Java source code to append to the method's body
- * @param lineSeparator line separator
- */
- public void appendBodyCode(String extraCode, String lineSeparator) {
- if (extraCode.length() == 0) {
- return;
- }
- if (bodyCode.length() > 0 && !bodyCode.toString().endsWith(lineSeparator)) {
- bodyCode.append(lineSeparator);
- }
- bodyCode.append(extraCode);
- }
-
- /**
- * Returns the Java source code for this method.
- *
- * @param lineSeparator line separator
- * @return the Java source code for this method
- */
- public String toString(String lineSeparator) {
- StringBuffer result = new StringBuffer();
- result.append(JavaFile.getModifiersText(modifiers));
- if (returnType != null) {
- result.append(returnType);
- result.append(' ');
- }
- result.append(name);
- result.append('(');
- if (arguments != null) {
- for (int i = 0; i < arguments.length; i++) {
- if (i > 0) {
- result.append(", ");
- }
- result.append(arguments[i].toString());
- }
- }
- result.append(") {");
- result.append(lineSeparator);
- if (bodyCode != null) {
- String formattedBodyCode = JavaFile.addIndentation(bodyCode.toString().trim(), 4, lineSeparator);
- if (formattedBodyCode.length() > 0) {
- result.append(formattedBodyCode);
- result.append(lineSeparator);
- }
- }
- result.append("}");
- return result.toString();
- }
-
- @Override
- public int compareTo(JavaMethod o) {
- return COMPARATOR.compare(this, o);
- }
-
- public static JavaMethod newMethod(int modifiers, String returnType, String name, String initializer, String[] exceptions, JavaArgument... arguments) {
- return new JavaMethod(modifiers, returnType, name, arguments, exceptions, initializer);
- }
-
- public static JavaMethod newMethod(int modifiers, String returnType, String name, String initializer, JavaArgument... arguments) {
- return newMethod(modifiers, returnType, name, initializer, new String[0], arguments);
- }
-
- public enum MethodOrder {
-
- statics(Modifier.STATIC, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- Statics methods --------------------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
- },
- constructors(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- Constructors -----------------------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- @Override
- public boolean accept(JavaMethod method) {
- return method.returnType == null;
- }
- },
- JAXXObject(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- JAXXObject implementation ----------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- private List<String> methods = Arrays.asList("applyDataBinding", "firePropertyChange", "getObjectById", "get$objectMap", "processDataBinding", "removeDataBinding");
-
- @Override
- public boolean accept(JavaMethod method) {
- return methods.contains(method.name);
- }
- },
- JAXXContext(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- JAXXContext implementation ---------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- private List<String> methods = Arrays.asList("getContextValue", "getDelegateContext", "getParentContainer", "removeContextValue", "setContextValue");
-
- @Override
- public boolean accept(JavaMethod method) {
- return methods.contains(method.name);
- }
- },
- JAXXValidation(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- JAXXValidation implementation ------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- private List<String> methods = Arrays.asList("getValidator", "getValidatorIds");
-
- @Override
- public boolean accept(JavaMethod method) {
- return methods.contains(method.name);
- }
- },
- events(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- Event methods ----------------------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- @Override
- public boolean accept(JavaMethod method) {
- return (method.name.startsWith("do") && method.name.indexOf("__") > -1);
- }
- },
- publicGetters(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- public acessor methods -------------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- @Override
- public boolean accept(JavaMethod method) {
- return (method.name.startsWith("get") || method.name.startsWith("is"));
- }
- },
- publicSetters(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- public mutator methods -------------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- @Override
- public boolean accept(JavaMethod method) {
- return (method.name.startsWith("set"));
- }
- },
- otherPublic(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- public mutator methods -------------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- @Override
- public boolean accept(int mod) {
- return super.accept(mod) && !Modifier.isStatic(mod);
- }
- },
- protectedGetters(Modifier.PROTECTED, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- protected acessors methods ---------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- @Override
- public boolean accept(JavaMethod method) {
- return (method.name.startsWith("get") || method.name.startsWith("is"));
- }
- },
- createMethod(Modifier.PROTECTED | Modifier.PRIVATE, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- ui creation methods ----------------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- @Override
- public boolean accept(JavaMethod method) {
- return method.name.startsWith("create") || method.name.startsWith("add") ||
- method.name.equals("$completeSetup") ||
- method.name.equals("$initialize");
- }
- },
- protecteds(Modifier.PROTECTED, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- Other protected methods ------------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
- },
- packageLocal(0, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- Package methods --------------------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
-
- @Override
- public boolean accept(int mod) {
- return !Modifier.isStatic(mod) && !Modifier.isPublic(mod) && !Modifier.isProtected(mod);
- }
- },
- privates(Modifier.PRIVATE, "/*---------------------------------------------------------------------------------*/\n" +
- "/*-- Private methods --------------------------------------------------------------*/\n" +
- "/*---------------------------------------------------------------------------------*/") {
- };
- private final String header;
- private int modifier;
-
- MethodOrder(int modifier, String header) {
- this.header = header;
- this.modifier = modifier;
- }
-
- public String getHeader() {
- return header;
- }
-
- public boolean accept(JavaMethod method) {
- return true;
- }
-
- public boolean accept(int mod) {
- return (mod & modifier) != 0;
- }
-
- public boolean accept(int mod, JavaMethod method) {
- return accept(mod) && accept(method);
- }
-
- public static MethodOrder valueOf(JavaMethod method, int scope) {
- for (MethodOrder o : values()) {
- if (o.accept(scope, method)) {
- return o;
- }
- }
- throw new IllegalArgumentException("could not find a " + MethodOrder.class + " for method " + method);
- }
-
- public void generate(StringBuffer buffer, List<JavaMethod> methods, String lineSeparator) {
- if (methods.isEmpty()) {
- return;
- }
- buffer.append(JavaFile.addIndentation(header, 4, lineSeparator));
- buffer.append(lineSeparator).append(lineSeparator);
- for (JavaMethod method : methods) {
- buffer.append(JavaFile.addIndentation(method.toString(lineSeparator), 4, lineSeparator));
- buffer.append(lineSeparator).append(lineSeparator);
- }
- }
- }
-
- public static EnumMap<MethodOrder, List<JavaMethod>> getSortedMethods(List<JavaMethod> methods) {
-
- EnumMap<MethodOrder, List<JavaMethod>> result = new EnumMap<MethodOrder, List<JavaMethod>>(MethodOrder.class);
- for (MethodOrder methodOrder : MethodOrder.values()) {
- result.put(methodOrder, new ArrayList<JavaMethod>());
- }
-
- EnumSet<MethodOrder> allConstants = EnumSet.allOf(MethodOrder.class);
- List<JavaMethod> allMethods = new ArrayList<JavaMethod>(methods);
- int[] scopes = new int[]{Modifier.STATIC, Modifier.PUBLIC, Modifier.PROTECTED, Modifier.PRIVATE};
- for (int scope : scopes) {
- EnumSet<MethodOrder> constants = getMethodOrderScope(allConstants, scope);
-
- Iterator<JavaMethod> itMethods = allMethods.iterator();
- while (itMethods.hasNext()) {
- JavaMethod method = itMethods.next();
- for (MethodOrder constant : constants) {
- if (constant.accept(method.getModifiers(), method)) {
- result.get(constant).add(method);
- itMethods.remove();
- break;
- }
- }
- }
- constants.clear();
- }
-
- if (!allMethods.isEmpty()) {
- throw new IllegalArgumentException("could not find a " + MethodOrder.class + " for method " + allMethods);
- }
-
- for (MethodOrder methodOrder : MethodOrder.values()) {
- // sort methods
- java.util.Collections.sort(result.get(methodOrder));
- }
- return result;
- }
-
- public static EnumSet<MethodOrder> getMethodOrderScope(EnumSet<MethodOrder> allConstants, int scope) {
- EnumSet<MethodOrder> constants = EnumSet.noneOf(MethodOrder.class);
- for (MethodOrder order : allConstants) {
- if (order.accept(scope)) {
- constants.add(order);
- }
- }
- return constants;
- }
- public static final Comparator<JavaMethod> COMPARATOR = new Comparator<JavaMethod>() {
-
- @Override
- public int compare(JavaMethod o1, JavaMethod o2) {
-
- /*int result;
- if ((result = compareStatic(o1, o2)) != 0) {
- return result;
- }
- if ((result = compareConstructor(o1, o2)) != 0) {
- return result;
- }
- if ((result = compareVisibility(o1, o2)) != 0) {
- return result;
- }*/
- return o1.name.compareTo(o2.name);
- }
-
- public int compareStatic(JavaMethod o1, JavaMethod o2) {
- if (Modifier.isStatic(o1.modifiers) && !Modifier.isStatic(o2.modifiers)) {
- return -1;
- }
- if (!Modifier.isStatic(o1.modifiers) && Modifier.isStatic(o2.modifiers)) {
- return 1;
- }
- return 0;
- }
-
- public int compareConstructor(JavaMethod o1, JavaMethod o2) {
- if (o1.returnType == null && o2.returnType != null) {
- return -1;
- }
- if (o1.returnType != null && o2.returnType == null) {
- return 1;
- }
- return 0;
- }
-
- public int compareVisibility(JavaMethod o1, JavaMethod o2) {
- if (Modifier.isPublic(o1.modifiers) && !Modifier.isPublic(o2.modifiers)) {
- return -1;
- }
- if (!Modifier.isPublic(o1.modifiers) && Modifier.isPublic(o2.modifiers)) {
- return 1;
- }
- if (Modifier.isProtected(o1.modifiers) && !Modifier.isProtected(o2.modifiers)) {
- return -1;
- }
- if (!Modifier.isProtected(o1.modifiers) && Modifier.isProtected(o2.modifiers)) {
- return 1;
- }
- if (Modifier.isPrivate(o1.modifiers) && !Modifier.isPrivate(o2.modifiers)) {
- return -1;
- }
- if (!Modifier.isPrivate(o1.modifiers) && Modifier.isPrivate(o2.modifiers)) {
- return 1;
- }
- return 0;
- }
- };
-}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/StylesheetHelper.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/StylesheetHelper.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/StylesheetHelper.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -11,7 +11,6 @@
import jaxx.compiler.reflect.MethodDescriptor;
import jaxx.compiler.tags.DefaultObjectHandler;
import jaxx.compiler.tags.TagManager;
-import jaxx.compiler.types.TypeManager;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@@ -119,7 +118,7 @@
pseudoClass = pseudoClass.substring(1, pseudoClass.length() - 1).trim();
pseudoClass = replaceObjectReferences(pseudoClass, object.getJavaCode());
String dest = object.getId() + ".style." + pseudoClass + ".add";
- String destCode = TypeManager.getJavaCode(dest);
+ String destCode = compiler.getJavaCode(dest);
if (compiler.haveProcessDataBinding()) {
compiler.appendProcessDataBinding("else ");
}
@@ -229,7 +228,7 @@
pseudoClass = pseudoClass.substring(1, pseudoClass.length() - 1).trim();
pseudoClass = replaceObjectReferences(pseudoClass, object.getJavaCode());
String dest = object.getId() + ".style." + pseudoClass + ".remove";
- String destCode = TypeManager.getJavaCode(dest);
+ String destCode = compiler.getJavaCode(dest);
if (compiler.haveProcessDataBinding()) {
compiler.appendProcessDataBinding("else ");
}
@@ -383,13 +382,13 @@
String dataBinding = compiler.processDataBindings(e.getValue(), type);
String valueCode;
if (dataBinding != null) {
- valueCode = "new jaxx.runtime.css.DataBinding(" + TypeManager.getJavaCode(object.getId() + "." + property + "." + priority) + ")";
+ valueCode = "new jaxx.runtime.css.DataBinding(" + compiler.getJavaCode(object.getId() + "." + property + "." + priority) + ")";
new DataBinding(dataBinding, object.getId() + "." + property + "." + priority, handler.getSetPropertyCode(object.getJavaCode(),
property, "(" + JAXXCompiler.getCanonicalName(type) + ") " + dataBinding, compiler), compiler).compile(false);
} else {
try {
Class<?> typeClass = type != null ? ClassDescriptorLoader.getClass(type.getName(), type.getClassLoader()) : null;
- valueCode = TypeManager.getJavaCode(TypeManager.convertFromString(e.getValue(), typeClass));
+ valueCode = compiler.getJavaCode(compiler.convertFromString(e.getValue(), typeClass));
} catch (ClassNotFoundException ex) {
compiler.reportError("could not find class " + type.getName());
return;
@@ -399,7 +398,7 @@
buffer.append("java.lang.Object ");
valueDeclared = true;
}
- buffer.append("value = jaxx.runtime.css.Pseudoclasses.applyProperty(").append(compiler.getOutputClassName()).append(".this, ").append(object.getJavaCode()).append(", ").append(TypeManager.getJavaCode(property)).append(", ").append(valueCode).append(", jaxx.runtime.css.Pseudoclasses.wrap(").append(handler.getGetPropertyCode(object.getJavaCode(), property, compiler)).append("), ").append(priority).append(");").append(JAXXCompiler.getLineSeparator());
+ buffer.append("value = jaxx.runtime.css.Pseudoclasses.applyProperty(").append(compiler.getOutputClassName()).append(".this, ").append(object.getJavaCode()).append(", ").append(compiler.getJavaCode(property)).append(", ").append(valueCode).append(", jaxx.runtime.css.Pseudoclasses.wrap(").append(handler.getGetPropertyCode(object.getJavaCode(), property, compiler)).append("), ").append(priority).append(");").append(JAXXCompiler.getLineSeparator());
buffer.append("if (!(value instanceof jaxx.runtime.css.DataBinding)) {").append(JAXXCompiler.getLineSeparator());
String unwrappedValue = unwrap(type, "value");
buffer.append(" ").append(handler.getSetPropertyCode(object.getJavaCode(), property, "(" + JAXXCompiler.getCanonicalName(type) +
@@ -431,13 +430,13 @@
String dataBinding = compiler.processDataBindings(e.getValue(), type);
String valueCode;
if (dataBinding != null) {
- valueCode = "new jaxx.runtime.css.DataBinding(" + TypeManager.getJavaCode(object.getId() + "." + property + "." + priority) + ")";
+ valueCode = "new jaxx.runtime.css.DataBinding(" + compiler.getJavaCode(object.getId() + "." + property + "." + priority) + ")";
new DataBinding(dataBinding, object.getId() + "." + property + "." + priority, handler.getSetPropertyCode(object.getJavaCode(),
property, "(" + JAXXCompiler.getCanonicalName(type) + ") " + dataBinding, compiler), compiler).compile(false);
} else {
try {
Class<?> typeClass = type != null ? ClassDescriptorLoader.getClass(type.getName(), type.getClassLoader()) : null;
- valueCode = TypeManager.getJavaCode(TypeManager.convertFromString(e.getValue(), typeClass));
+ valueCode = compiler.getJavaCode(compiler.convertFromString(e.getValue(), typeClass));
} catch (ClassNotFoundException ex) {
compiler.reportError("could not find class " + type.getName());
return;
@@ -447,7 +446,7 @@
buffer.append("java.lang.Object ");
valueDeclared = true;
}
- buffer.append("value = jaxx.runtime.css.Pseudoclasses.removeProperty(").append(compiler.getOutputClassName()).append(".this, ").append(object.getJavaCode()).append(", ").append(TypeManager.getJavaCode(property)).append(", ").append(valueCode).append(", jaxx.runtime.css.Pseudoclasses.wrap(").append(handler.getGetPropertyCode(object.getJavaCode(), property, compiler)).append("), ").append(priority).append(");").append(JAXXCompiler.getLineSeparator());
+ buffer.append("value = jaxx.runtime.css.Pseudoclasses.removeProperty(").append(compiler.getOutputClassName()).append(".this, ").append(object.getJavaCode()).append(", ").append(compiler.getJavaCode(property)).append(", ").append(valueCode).append(", jaxx.runtime.css.Pseudoclasses.wrap(").append(handler.getGetPropertyCode(object.getJavaCode(), property, compiler)).append("), ").append(priority).append(");").append(JAXXCompiler.getLineSeparator());
buffer.append("if (!(value instanceof jaxx.runtime.css.DataBinding)) {").append(JAXXCompiler.getLineSeparator());
String unwrappedValue = unwrap(type, "value");
buffer.append(" ").append(handler.getSetPropertyCode(object.getJavaCode(), property, "(" + JAXXCompiler.getCanonicalName(type) +
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/BoxedCompiledObjectDecorator.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/BoxedCompiledObjectDecorator.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/BoxedCompiledObjectDecorator.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -3,7 +3,7 @@
import jaxx.compiler.CompiledObject;
import jaxx.compiler.CompiledObject.ChildRef;
import jaxx.compiler.JAXXCompiler;
-import jaxx.compiler.JavaFile;
+import jaxx.compiler.io.JavaFile;
import jaxx.runtime.SwingUtil;
/**
@@ -16,6 +16,11 @@
public class BoxedCompiledObjectDecorator extends DefaultCompiledObjectDecorator {
@Override
+ public String getName() {
+ return "boxed";
+ }
+
+ @Override
public void finalizeCompiler(JAXXCompiler compiler, CompiledObject root, CompiledObject object, JavaFile javaFile, String packageName, String className, String fullClassName) {
CompiledObject parent = object.getParent();
for (ChildRef child : parent.getChilds()) {
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/CompiledObjectDecorator.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/CompiledObjectDecorator.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/CompiledObjectDecorator.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -3,7 +3,7 @@
import jaxx.compiler.CompiledObject;
import jaxx.compiler.CompilerException;
import jaxx.compiler.JAXXCompiler;
-import jaxx.compiler.JavaFile;
+import jaxx.compiler.io.JavaFile;
/**
*
@@ -16,6 +16,8 @@
*/
public interface CompiledObjectDecorator {
+ String getName();
+
String createCompleteSetupMethod(JAXXCompiler compiler, CompiledObject object, JavaFile javaFile, StringBuffer initDataBindings);
boolean createInitializer(JAXXCompiler compiler, CompiledObject root, CompiledObject object, StringBuffer code, boolean lastWasMethodCall);
Deleted: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/CompiledObjectDecoratorManager.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/CompiledObjectDecoratorManager.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/CompiledObjectDecoratorManager.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,59 +0,0 @@
-package jaxx.compiler.decorators;
-
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- *
- * @author chemit
- * @since 2.0.0
- */
-public class CompiledObjectDecoratorManager {
-
- protected static Map<String, CompiledObjectDecorator> cache;
-
- public static void registerDecorator(String key, Class<? extends CompiledObjectDecorator> klass) {
- synchronized (getCache()) {
- if (getCache().containsKey(key)) {
- throw new IllegalArgumentException("the decorator with key [" + key + "] is already registred! use another key name");
- }
- try {
- getCache().put(key, klass.newInstance());
- } catch (InstantiationException ex) {
- throw new IllegalArgumentException("could not create decorator " + klass + " for reason " + ex.getMessage(), ex);
- } catch (IllegalAccessException ex) {
- throw new IllegalArgumentException("could not create decorator " + klass + " for reason " + ex.getMessage(), ex);
- }
- }
- }
-
- public static CompiledObjectDecorator getDecorator(String name) {
- CompiledObjectDecorator decorator = getCache().get(name);
- if (decorator == null) {
- throw new IllegalArgumentException("could not find decorator with key " + name + " (known decorators : " + getCache().keySet());
- }
- return decorator;
- }
-
- public static CompiledObjectDecorator getDecorator(Class<?> type) {
- for (CompiledObjectDecorator decorator : getCache().values()) {
- if (type == decorator.getClass()) {
- return decorator;
- }
- }
- return null;
- }
-
- protected static synchronized Map<String, CompiledObjectDecorator> getCache() {
- if (cache == null) {
- cache = new TreeMap<String, CompiledObjectDecorator>();
- }
- return cache;
- }
-
- public static void reset() {
- if (cache != null) {
- cache.clear();
- }
- }
-}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -3,11 +3,10 @@
import jaxx.compiler.CompiledObject;
import jaxx.compiler.CompilerException;
import jaxx.compiler.JAXXCompiler;
-import jaxx.compiler.JavaField;
-import jaxx.compiler.JavaFile;
-import jaxx.compiler.JavaMethod;
+import jaxx.compiler.io.JavaField;
+import jaxx.compiler.io.JavaFile;
+import jaxx.compiler.io.JavaMethod;
import jaxx.compiler.ScriptInitializer;
-import jaxx.compiler.types.TypeManager;
import java.lang.reflect.Modifier;
import java.util.Map.Entry;
@@ -21,21 +20,27 @@
public class DefaultCompiledObjectDecorator implements CompiledObjectDecorator {
@Override
+ public String getName() {
+ return "default";
+ }
+
+ @Override
public void finalizeCompiler(JAXXCompiler compiler, CompiledObject root, CompiledObject object, JavaFile javaFile, String packageName, String className, String fullClassName) {
if (!object.isOverride() && !(object instanceof ScriptInitializer)) {
String id = object.getId();
int access = id.startsWith("$") ? Modifier.PRIVATE : Modifier.PROTECTED;
if (object == root) {
- javaFile.addField(new JavaField(access, fullClassName, id, "this"));
+ javaFile.addField(new JavaField(access, className, id, false, "this"));
+// javaFile.addField(new JavaField(access, fullClassName, id, false, "this"));
} else {
//TC -20081017 can have generic on compiled Object
- javaFile.addField(JavaField.newField(access, JAXXCompiler.getCanonicalName(object), id), object.isJavaBean());
+ javaFile.addField(JavaField.newField(access, JAXXCompiler.getCanonicalName(object), id, object.isOverride()), object.isJavaBean());
}
}
if (!compiler.inlineCreation(object) && object != root) {
- javaFile.addMethod(JavaMethod.newMethod(Modifier.PROTECTED, "void", object.getCreationMethodName(), getCreationCode(compiler, object)));
+ javaFile.addMethod(JavaMethod.newMethod(Modifier.PROTECTED, "void", object.getCreationMethodName(), getCreationCode(compiler, object), object.isOverride()));
}
}
@@ -45,29 +50,35 @@
return object.getInitializationCode(compiler);
}
StringBuffer result = new StringBuffer();
+ String eol = JAXXCompiler.getLineSeparator();
if (object.isOverride() && object.getOverrideType() == object.getObjectClass()) {
//TC-20090309 on utilise le super code quand l'objet est de meme type
result.append("super.").append(object.getCreationMethodName()).append("();");
} else {
- result.append(object.getId());
- result.append(" = ");
+ String init = object.getId() + " = ";
+// result.append(object.getId());
+// result.append(" = ");
if (object.isJavaBean() && object.getJavaBeanInitCode() != null) {
- result.append(object.getJavaBeanInitCode()).append(";");
+ init += object.getJavaBeanInitCode();
+// result.append(object.getJavaBeanInitCode()).append(";");
} else {
String constructorParams = object.getConstructorParams();
+ String canonicalName = JAXXCompiler.getCanonicalName(object);
if (constructorParams != null) {
//TC - 20081017 compiledObject can have generics
- result.append(" new ").append(JAXXCompiler.getCanonicalName(object)).append("(").append(constructorParams).append(");");
- //result.append("(").append(getCanonicalName(object.getObjectClass())).append(") new ").append(getCanonicalName(object.getObjectClass())).append("(").append(constructorParams).append(");");
+ init += "new " + canonicalName + "(" + constructorParams + ")";
+// result.append(" new ").append(canonicalName).append("(").append(constructorParams).append(");");
} else {
//TC - 20081017 compiledObject can have generics
- result.append("new ").append(JAXXCompiler.getCanonicalName(object)).append("();");
+ init += "new " + canonicalName + "()";
+// result.append("new ").append(canonicalName).append("();");
}
}
- result.append(JAXXCompiler.getLineSeparator());
- result.append("$objectMap.put(").append(TypeManager.getJavaCode(object.getId())).append(", ").append(object.getId()).append(");");
+ result.append(eol);
+ result.append("$objectMap.put(").append(compiler.getJavaCode(object.getId())).append(", ").append(init).append(");");
+// result.append("$objectMap.put(").append(TypeManager.getJavaCode(object.getId())).append(", ").append(object.getId()).append(");");
}
- result.append(JAXXCompiler.getLineSeparator());
+ result.append(eol);
String initCode = object.getInitializationCode(compiler);
if (initCode != null && initCode.length() > 0) {
result.append(initCode);
@@ -87,41 +98,42 @@
}
}
+ String eol = JAXXCompiler.getLineSeparator();
//TC - 20081017 only generate the method if not empty ?
if (object.getId().startsWith("$")) {
- code.append(object.getAdditionCode()).append(JAXXCompiler.getLineSeparator());
+ code.append(object.getAdditionCode()).append(eol);
} else {
String additionCode = object.getAdditionCode();
if (additionCode.length() > 0) {
- code.append(object.getAdditionMethodName()).append("();").append(JAXXCompiler.getLineSeparator());
- additionCode = "if (!allComponentsCreated) {" + JAXXCompiler.getLineSeparator() + " return;" + JAXXCompiler.getLineSeparator() + "}" + JAXXCompiler.getLineSeparator() + additionCode;
- javaFile.addMethod(JavaMethod.newMethod(Modifier.PROTECTED, "void", object.getAdditionMethodName(), additionCode));
+ code.append(object.getAdditionMethodName()).append("();").append(eol);
+ additionCode = "if (!allComponentsCreated) {" + eol + " return;" + eol + "}" + eol + additionCode;
+ javaFile.addMethod(JavaMethod.newMethod(Modifier.PROTECTED, "void", object.getAdditionMethodName(), additionCode, false));
}
}
- //code.append(getLineSeparator());
return code.toString();
}
@Override
public boolean createInitializer(JAXXCompiler compiler, CompiledObject root, CompiledObject object, StringBuffer code, boolean lastWasMethodCall) {
+ String eol = JAXXCompiler.getLineSeparator();
if (object == root) {
String rootCode = root.getInitializationCode(compiler);
if (rootCode != null && rootCode.length() > 0) {
code.append(rootCode);
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
}
} else {
if (!object.isOverride()) {
if (compiler.inlineCreation(object)) {
if (lastWasMethodCall) {
lastWasMethodCall = false;
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
}
code.append(getCreationCode(compiler, object));
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
} else {
code.append(object.getCreationMethodName()).append("();");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
lastWasMethodCall = true;
}
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -3,9 +3,9 @@
import jaxx.compiler.CompiledObject;
import jaxx.compiler.CompilerConfiguration;
import jaxx.compiler.JAXXCompiler;
-import jaxx.compiler.JavaArgument;
-import jaxx.compiler.JavaFile;
-import jaxx.compiler.JavaMethod;
+import jaxx.compiler.io.JavaArgument;
+import jaxx.compiler.io.JavaFile;
+import jaxx.compiler.io.JavaMethod;
import java.lang.reflect.Modifier;
import java.util.Iterator;
@@ -24,6 +24,11 @@
*/
protected static Set<String> helpIds = new java.util.HashSet<String>();
+ @Override
+ public String getName() {
+ return "help";
+ }
+
protected String getBrokerFQN(JAXXCompiler compiler) {
String helpBrokerFQN = compiler.getConfiguration().getHelpBrokerFQN();
return helpBrokerFQN;
@@ -50,18 +55,18 @@
javaFile.addInterface(JAXXCompiler.getCanonicalName(validatorInterface) + "<" + helpBrokerFQN + ">");
javaFile.addMethod(JavaMethod.newMethod(Modifier.PUBLIC, "void", "registerHelpId",
- "broker.installUI(component, helpId);",
+ "broker.installUI(component, helpId);",true,
new JavaArgument(helpBrokerFQN, "broker"),
new JavaArgument("Component", "component"),
new JavaArgument("String", "helpId")));
javaFile.addMethod(JavaMethod.newMethod(Modifier.PUBLIC, "void", "showHelp",
- "getBroker().showHelp(this, helpId);",
+ "getBroker().showHelp(this, helpId);",true,
new JavaArgument("String", "helpId")));
StringBuilder buffer = new StringBuilder();
- String lineSeparator = JAXXCompiler.getLineSeparator();
+ String eol = JAXXCompiler.getLineSeparator();
if (options.isGenerateHelp()) {
@@ -72,7 +77,7 @@
CompiledObject o = itr.next();
String helpID = getHelpId(o);
if (helpID != null) {
- buffer.append(lineSeparator);
+ buffer.append(eol);
// detects a helpId to register
buffer.append("registerHelpId(_broker, " + o.getJavaCode() + ", " + helpID + ");");
//keep the helpID for helpSet generation
@@ -84,8 +89,8 @@
StringBuilder extraCode = new StringBuilder(helpBrokerFQN).append(" _broker = getBroker();");
- buffer.append(lineSeparator).append("_broker.prepareUI(this);");
- buffer.append(lineSeparator);
+ buffer.append(eol).append("_broker.prepareUI(this);");
+ buffer.append(eol);
// add the calls
compiler.appendLateInitializer(extraCode.toString());
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/Generator.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/Generator.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/Generator.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -2,7 +2,7 @@
import jaxx.compiler.CompiledObject;
import jaxx.compiler.JAXXCompiler;
-import jaxx.compiler.JavaFile;
+import jaxx.compiler.io.JavaFile;
/**
* TODO javadoc!
Deleted: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/GeneratorManager.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/GeneratorManager.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/GeneratorManager.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,42 +0,0 @@
-package jaxx.compiler.generators;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ServiceLoader;
-
-/**
- *
- * @author chemit
- * @since 2.0.0
- */
-public class GeneratorManager {
-
- protected static List<Generator> generators;
-
- public static List<Generator> getGenerators() {
- if (generators == null) {
- loadGenerators();
- }
- return generators;
- }
-
- public static void addGenerator(Generator g) {
- getGenerators().add(g);
- }
-
- public static void clear() {
- if (generators != null) {
- generators.clear();
- generators = null;
- }
- }
-
- protected static void loadGenerators() {
- if (generators == null) {
- generators = new ArrayList<Generator>();
- for (Generator generator : ServiceLoader.load(Generator.class)) {
- generators.add(generator);
- }
- }
- }
-}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/JAXXObjectGenerator.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/JAXXObjectGenerator.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/JAXXObjectGenerator.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,5 +1,9 @@
package jaxx.compiler.generators;
+import jaxx.compiler.io.JavaMethod;
+import jaxx.compiler.io.JavaArgument;
+import jaxx.compiler.io.JavaField;
+import jaxx.compiler.io.JavaFile;
import jaxx.compiler.*;
import jaxx.runtime.Base64Coder;
import jaxx.compiler.CompilerException;
@@ -8,7 +12,6 @@
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.reflect.FieldDescriptor;
import jaxx.compiler.reflect.MethodDescriptor;
-import jaxx.compiler.types.TypeManager;
import jaxx.runtime.JAXXObject;
import jaxx.runtime.JAXXObjectDescriptor;
import jaxx.runtime.JAXXContext;
@@ -17,9 +20,7 @@
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
-import java.lang.reflect.Modifier;
-import static java.lang.reflect.Modifier.FINAL;
-import static java.lang.reflect.Modifier.PROTECTED;
+import static java.lang.reflect.Modifier.*;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -36,75 +37,77 @@
/** log */
protected static final Log log = LogFactory.getLog(JAXXObjectGenerator.class);
+ protected static final JavaField SERIAL_VERSION_UID_FIELD = JavaField.newField(PRIVATE | STATIC | FINAL,
+ "long", "serialVersionUID", false, "1L");
protected static final JavaField ACTIVE_BINDINGS_FIELD = JavaField.newField(PROTECTED,
- "java.util.List<Object>", "$activeBindings", "new ArrayList<Object>()");
+ "java.util.List<Object>", "$activeBindings", false, "new ArrayList<Object>()");
protected static final JavaField BINDING_SOURCES_FIELD = JavaField.newField(PROTECTED,
- "java.util.Map<String,Object>", "$bindingSources", "new HashMap<String,Object>()");
+ "java.util.Map<String,Object>", "$bindingSources", false, "new HashMap<String,Object>()");
protected static final JavaField OBJECT_MAP_FIELD = JavaField.newField(PROTECTED,
- "Map<String,Object>", "$objectMap", "new HashMap<String,Object>()");
- protected static final JavaField ALL_COMPONENTS_CREATED_FIELD = JavaField.newField(java.lang.reflect.Modifier.PRIVATE,
- "boolean", "allComponentsCreated");
- protected static final JavaField CONTEXT_INITIALIZED = JavaField.newField(java.lang.reflect.Modifier.PRIVATE,
- "boolean", "contextInitialized", "true");
- protected static final JavaField PREVIOUS_VALUES_FIELD = JavaField.newField(0,
- "java.util.Map", "$previousValues", "new java.util.HashMap()");
+ "Map<String,Object>", "$objectMap", true, "new HashMap<String,Object>()");
+ protected static final JavaField ALL_COMPONENTS_CREATED_FIELD = JavaField.newField(PRIVATE,
+ "boolean", "allComponentsCreated", false);
+ protected static final JavaField CONTEXT_INITIALIZED = JavaField.newField(PRIVATE,
+ "boolean", "contextInitialized", false, "true");
+ protected static final JavaField PREVIOUS_VALUES_FIELD = JavaField.newField(PROTECTED,
+ "java.util.Map<?,?>", "$previousValues", false, "new java.util.HashMap<Object,Object>()");
protected static final JavaField DELEGATE_CONTEXT_FIELD = JavaField.newField(PROTECTED,
- JAXXContext.class.getName(), "delegateContext");
+ JAXXContext.class.getName(), "delegateContext", true);
protected static final JavaField PROPERTY_CHANGE_SUPPORT_FIELD = JavaField.newField(0,
- "java.beans.PropertyChangeSupport", "$propertyChangeSupport");
- protected static final JavaMethod GET_CONTEXT_VALUE_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "<T> T", "getContextValue",
- "return delegateContext.getContextValue(clazz, null);",
+ "java.beans.PropertyChangeSupport", "$propertyChangeSupport", false);
+ protected static final JavaMethod GET_CONTEXT_VALUE_METHOD = JavaMethod.newMethod(PUBLIC, "<T> T", "getContextValue",
+ "return delegateContext.getContextValue(clazz, null);", true,
new JavaArgument("Class<T>", "clazz"));
- protected static final JavaMethod GET_CONTEXT_VALUE_NAMED_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "<T> T", "getContextValue",
- "return delegateContext.getContextValue(clazz, name);",
+ protected static final JavaMethod GET_CONTEXT_VALUE_NAMED_METHOD = JavaMethod.newMethod(PUBLIC, "<T> T", "getContextValue",
+ "return delegateContext.getContextValue(clazz, name);", true,
new JavaArgument("Class<T>", "clazz"), new JavaArgument("String", "name"));
- protected static final JavaMethod SET_CONTEXT_VALUE_NAMED_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "<T> void", "setContextValue",
- "delegateContext.setContextValue(o, name);",
+ protected static final JavaMethod SET_CONTEXT_VALUE_NAMED_METHOD = JavaMethod.newMethod(PUBLIC, "<T> void", "setContextValue",
+ "delegateContext.setContextValue(o, name);", true,
new JavaArgument("T", "o"), new JavaArgument("String", "name"));
- protected static final JavaMethod SET_CONTEXT_VALUE_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "<T> void", "setContextValue",
- "delegateContext.setContextValue(o, null);",
+ protected static final JavaMethod SET_CONTEXT_VALUE_METHOD = JavaMethod.newMethod(PUBLIC, "<T> void", "setContextValue",
+ "delegateContext.setContextValue(o, null);", true,
new JavaArgument("T", "o"));
- protected static final JavaMethod REMOVE_CONTEXT_VALUE_NAMED_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "<T> void", "removeContextValue",
- "delegateContext.removeContextValue(clazz, name);",
+ protected static final JavaMethod REMOVE_CONTEXT_VALUE_NAMED_METHOD = JavaMethod.newMethod(PUBLIC, "<T> void", "removeContextValue",
+ "delegateContext.removeContextValue(clazz, name);", true,
new JavaArgument("Class<T>", "clazz"), new JavaArgument("String", "name"));
- protected static final JavaMethod REMOVE_CONTEXT_VALUE_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "<T> void", "removeContextValue",
- "delegateContext.removeContextValue(clazz, null);",
+ protected static final JavaMethod REMOVE_CONTEXT_VALUE_METHOD = JavaMethod.newMethod(PUBLIC, "<T> void", "removeContextValue",
+ "delegateContext.removeContextValue(clazz, null);", true,
new JavaArgument("Class<T>", "clazz"));
- protected static final JavaMethod GET_PARENT_CONTAINER_MORE_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "<O extends Container> O", "getParentContainer",
- "return delegateContext.getParentContainer(source, clazz);",
+ protected static final JavaMethod GET_PARENT_CONTAINER_MORE_METHOD = JavaMethod.newMethod(PUBLIC, "<O extends Container> O", "getParentContainer",
+ "return delegateContext.getParentContainer(source, clazz);", true,
new JavaArgument("Object", "source"), new JavaArgument("Class<O>", "clazz"));
- protected static final JavaMethod GET_PARENT_CONTAINER_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "<O extends Container> O", "getParentContainer",
- "return delegateContext.getParentContainer(clazz);",
+ protected static final JavaMethod GET_PARENT_CONTAINER_METHOD = JavaMethod.newMethod(PUBLIC, "<O extends Container> O", "getParentContainer",
+ "return delegateContext.getParentContainer(clazz);", true,
new JavaArgument("Class<O>", "clazz"));
- protected static final JavaMethod GET_OBJECT_BY_ID_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "java.lang.Object", "getObjectById",
- "return $objectMap.get(id);",
+ protected static final JavaMethod GET_OBJECT_BY_ID_METHOD = JavaMethod.newMethod(PUBLIC, "java.lang.Object", "getObjectById",
+ "return $objectMap.get(id);", true,
new JavaArgument("String", "id"));
- protected static final JavaMethod GET_JAXX_OBJECT_DESCRIPTOR_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC | java.lang.reflect.Modifier.STATIC, "jaxx.runtime.JAXXObjectDescriptor", "$getJAXXObjectDescriptor",
- "return jaxx.runtime.Util.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);");
- protected static final JavaMethod PROCESS_DATA_BINDING_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "void", "processDataBinding",
- "processDataBinding(dest, false);",
+ protected static final JavaMethod GET_JAXX_OBJECT_DESCRIPTOR_METHOD = JavaMethod.newMethod(PUBLIC | STATIC, "jaxx.runtime.JAXXObjectDescriptor", "$getJAXXObjectDescriptor",
+ "return jaxx.runtime.Util.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);", false);
+ protected static final JavaMethod PROCESS_DATA_BINDING_METHOD = JavaMethod.newMethod(PUBLIC, "void", "processDataBinding",
+ "processDataBinding(dest, false);", true,
new JavaArgument("String", "dest"));
- protected static final JavaMethod FIRE_PROPERTY_CHANGE_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "void", "firePropertyChange",
- "super.firePropertyChange(propertyName, oldValue, newValue);",
+ protected static final JavaMethod FIRE_PROPERTY_CHANGE_METHOD = JavaMethod.newMethod(PUBLIC, "void", "firePropertyChange",
+ "super.firePropertyChange(propertyName, oldValue, newValue);", true,
new JavaArgument("String", "propertyName"), new JavaArgument("Object", "oldValue"), new JavaArgument("Object", "newValue"));
- protected static final JavaMethod FIRE_PROPERTY_CHANGE_NAMED_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "void", "firePropertyChange",
- "$getPropertyChangeSupport().firePropertyChange(propertyName, oldValue, newValue);",
+ protected static final JavaMethod FIRE_PROPERTY_CHANGE_NAMED_METHOD = JavaMethod.newMethod(PUBLIC, "void", "firePropertyChange",
+ "$getPropertyChangeSupport().firePropertyChange(propertyName, oldValue, newValue);", true,
new JavaArgument("String", "propertyName"), new JavaArgument("Object", "oldValue"), new JavaArgument("Object", "newValue"));
protected static final JavaMethod GET_PROPERTY_CHANGE_SUPPORT_METHOD = JavaMethod.newMethod(0, "java.beans.PropertyChangeSupport", "$getPropertyChangeSupport",
"if ($propertyChangeSupport == null)\n" +
" $propertyChangeSupport = new PropertyChangeSupport(this);\n" +
- "return $propertyChangeSupport;");
- protected static final JavaMethod ADD_PROPERTY_CHANGE_SUPPORT_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "void", "addPropertyChangeListener",
- "$getPropertyChangeSupport().addPropertyChangeListener(listener);",
+ "return $propertyChangeSupport;", false);
+ protected static final JavaMethod ADD_PROPERTY_CHANGE_SUPPORT_METHOD = JavaMethod.newMethod(PUBLIC, "void", "addPropertyChangeListener",
+ "$getPropertyChangeSupport().addPropertyChangeListener(listener);", true,
new JavaArgument("java.beans.PropertyChangeListener", "listener"));
- protected static final JavaMethod ADD_PROPERTY_CHANGE_SUPPORT_NAMED_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "void", "addPropertyChangeListener",
- "$getPropertyChangeSupport().addPropertyChangeListener(property, listener);",
+ protected static final JavaMethod ADD_PROPERTY_CHANGE_SUPPORT_NAMED_METHOD = JavaMethod.newMethod(PUBLIC, "void", "addPropertyChangeListener",
+ "$getPropertyChangeSupport().addPropertyChangeListener(property, listener);", true,
new JavaArgument("String", "property"), new JavaArgument("java.beans.PropertyChangeListener", "listener"));
- protected static final JavaMethod REMOVE_PROPERTY_CHANGE_SUPPORT_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "void", "removePropertyChangeListener",
- "$getPropertyChangeSupport().removePropertyChangeListener(listener);",
+ protected static final JavaMethod REMOVE_PROPERTY_CHANGE_SUPPORT_METHOD = JavaMethod.newMethod(PUBLIC, "void", "removePropertyChangeListener",
+ "$getPropertyChangeSupport().removePropertyChangeListener(listener);", true,
new JavaArgument("java.beans.PropertyChangeListener", "listener"));
- protected static final JavaMethod REMOVE_PROPERTY_CHANGE_SUPPORT_NAMED_METHOD = JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, "void", "removePropertyChangeListener",
- "$getPropertyChangeSupport().removePropertyChangeListener(property, listener);",
+ protected static final JavaMethod REMOVE_PROPERTY_CHANGE_SUPPORT_NAMED_METHOD = JavaMethod.newMethod(PUBLIC, "void", "removePropertyChangeListener",
+ "$getPropertyChangeSupport().removePropertyChangeListener(property, listener);", true,
new JavaArgument("String", "property"), new JavaArgument("java.beans.PropertyChangeListener", "listener"));
@Override
@@ -117,8 +120,8 @@
//Map<String, CompiledObject> objects = compiler.getObjects();
ClassDescriptor superclass = root.getObjectClass();
boolean superclassIsJAXXObject = ClassDescriptorLoader.getClassDescriptor(JAXXObject.class).isAssignableFrom(superclass);
- javaFile.setModifiers(Modifier.PUBLIC);
- javaFile.setClassName(fullClassName);
+ javaFile.setModifiers(PUBLIC);
+ javaFile.setName(fullClassName);
javaFile.setSuperClass(JAXXCompiler.getCanonicalName(superclass));
javaFile.setSuperclassIsJAXXObject(superclassIsJAXXObject);
@@ -130,27 +133,13 @@
for (CompiledObject object : compiler.getObjects().values()) {
CompiledObjectDecorator decorator = object.getDecorator();
decorator.finalizeCompiler(compiler, root, object, javaFile, packageName, className, fullClassName);
-
- /*if (!object.isOverride() && !(object instanceof ScriptInitializer)) {
- String id = object.getId();
- int access = id.startsWith("$") ? Modifier.PRIVATE : Modifier.PROTECTED;
- if (object == root) {
- javaFile.addField(new JavaField(access, fullClassName, id, "this"));
- } else {
- //TC -20081017 can have generic on compiled Object
- javaFile.addField(JavaField.newField(access, JAXXCompiler.getCanonicalName(object), id), object.isJavaBean());
- }
- }
-
- if (!compiler.inlineCreation(object) && object != root) {
- javaFile.addMethod(JavaMethod.newMethod(Modifier.PROTECTED, "void", object.getCreationMethodName(), getCreationCode(compiler, object)));
- }*/
}
+ String eol = JAXXCompiler.getLineSeparator();
// DataBinding
for (DataBinding dataBinding : compiler.getDataBindings()) {
if (dataBinding.compile(true)) {
- compiler.getInitDataBindings().append("applyDataBinding(").append(TypeManager.getJavaCode(dataBinding.getId())).append(");").append(JAXXCompiler.getLineSeparator());
+ compiler.getInitDataBindings().append("applyDataBinding(").append(compiler.getJavaCode(dataBinding.getId())).append(");").append(eol);
}
}
@@ -158,27 +147,26 @@
boolean hasBind = compiler.getApplyDataBinding().length() > 0;
if (hasBind) {
compiler.appendApplyDataBinding(" else {");
- compiler.appendApplyDataBinding(JAXXCompiler.getLineSeparator());
+ compiler.appendApplyDataBinding(eol);
compiler.appendApplyDataBinding(" ");
}
compiler.appendApplyDataBinding("super.applyDataBinding($binding);");
- compiler.appendApplyDataBinding(JAXXCompiler.getLineSeparator());
+ compiler.appendApplyDataBinding(eol);
if (hasBind) {
compiler.appendApplyDataBinding(" return;");
- compiler.appendApplyDataBinding(JAXXCompiler.getLineSeparator());
+ compiler.appendApplyDataBinding(eol);
compiler.appendApplyDataBinding("}");
}
-
hasBind = compiler.getRemoveDataBinding().length() > 0;
if (hasBind) {
compiler.appendRemoveDataBinding(" else {");
- compiler.appendRemoveDataBinding(JAXXCompiler.getLineSeparator());
+ compiler.appendRemoveDataBinding(eol);
compiler.appendRemoveDataBinding(" ");
}
compiler.appendRemoveDataBinding("super.removeDataBinding($binding);");
- compiler.appendRemoveDataBinding(JAXXCompiler.getLineSeparator());
+ compiler.appendRemoveDataBinding(eol);
if (hasBind) {
compiler.appendRemoveDataBinding("}");
@@ -191,7 +179,7 @@
@Override
public void prepareJavaFile(CompiledObject root, JAXXCompiler compiler, JavaFile javaFile, String packageName, String className) throws ClassNotFoundException {
- String fullClassName = javaFile.getClassName();
+ String fullClassName = javaFile.getName();
String jaxxContextImplementorClass = compiler.getConfiguration().getJaxxContextClass().getName();
boolean superclassIsJAXXObject = javaFile.isSuperclassIsJAXXObject();
@@ -200,7 +188,7 @@
if (compiler.getConfiguration().isAddLogger()) {
javaFile.addImport(Log.class);
javaFile.addImport(LogFactory.class);
- javaFile.addField(JavaField.newField(Modifier.PUBLIC + Modifier.STATIC + FINAL, "Log", "log", "LogFactory.getLog(" + fullClassName + ".class)"));
+ javaFile.addField(JavaField.newField(PUBLIC + STATIC + FINAL, "Log", "log", false, "LogFactory.getLog(" + fullClassName + ".class)"));
}
// JAXXObject
@@ -210,7 +198,7 @@
javaFile.addField(ACTIVE_BINDINGS_FIELD);
// JAXXContext
- javaFile.addField(JavaField.newField(PROTECTED | FINAL, JAXXContext.class.getName(), "delegateContext", "new " + jaxxContextImplementorClass + "(this);"));
+ javaFile.addField(JavaField.newField(PROTECTED | FINAL, JAXXContext.class.getName(), "delegateContext", true, "new " + jaxxContextImplementorClass + "(this);"));
javaFile.addMethod(SET_CONTEXT_VALUE_METHOD);
javaFile.addMethod(SET_CONTEXT_VALUE_NAMED_METHOD);
javaFile.addMethod(GET_CONTEXT_VALUE_METHOD);
@@ -226,8 +214,8 @@
// DataBinding
javaFile.addMethod(PROCESS_DATA_BINDING_METHOD);
}
-
- javaFile.addField(ALL_COMPONENTS_CREATED_FIELD);
+ javaFile.addSimpleField(SERIAL_VERSION_UID_FIELD);
+ javaFile.addSimpleField(ALL_COMPONENTS_CREATED_FIELD);
boolean overrideContextInitialized = false;
FieldDescriptor[] scriptFields = compiler.getScriptFields();
for (FieldDescriptor f : scriptFields) {
@@ -237,22 +225,38 @@
}
}
if (!overrideContextInitialized) {
- javaFile.addField(CONTEXT_INITIALIZED);
+ javaFile.addSimpleField(CONTEXT_INITIALIZED);
}
- javaFile.addField(createJAXXObjectDescriptorField(compiler, javaFile));
+ javaFile.addSimpleField(createJAXXObjectDescriptorField(compiler, javaFile));
if (compiler.getStylesheet() != null) {
- javaFile.addField(PREVIOUS_VALUES_FIELD);
+ boolean needField = true;
+ if (superclassIsJAXXObject) {
+ // check alreay exists on parent
+ ClassDescriptor superclass = root.getObjectClass();
+ if (log.isDebugEnabled()) {
+ log.debug("superclass : " + superclass);
+ }
+ JAXXCompiler parentCompiler = compiler.getEngine().getJAXXCompiler(superclass.getName());
+ if (parentCompiler != null) {
+ needField = parentCompiler.getStylesheet() == null;
+ } else {
+ try {
+
+ superclass.getDeclaredFieldDescriptor(PREVIOUS_VALUES_FIELD.getName());
+ needField = false;
+ } catch (NoSuchFieldException ex) {
+ // field not found
+ }
+ }
+ if (needField && log.isDebugEnabled()) {
+ log.debug("no " + PREVIOUS_VALUES_FIELD.getName() + " field in super class");
+ }
+ }
+ if (needField) {
+ javaFile.addSimpleField(PREVIOUS_VALUES_FIELD);
+ }
}
- /*for (CompiledObject object : compiler.getObjects().values()) {
- List<CompiledObject.ChildRef> refList = object.getChilds();
- if (refList==null || refList.isEmpty()) {
- continue;
- }
- for (ChildRef childRef : refList) {
- childRef.addToAdditionCode(buffer);
- }
- }*/
//TC 20090228 - only generate constructors if not done in scripts
boolean constructorDetected = false;
MethodDescriptor[] methods = compiler.getScriptMethods();
@@ -279,13 +283,13 @@
javaFile.addMethod(createCompleteSetupMethod(compiler, javaFile, compiler.getInitDataBindings()));
-
- javaFile.addMethod(JavaMethod.newMethod(Modifier.PUBLIC, "void", "applyDataBinding",
+ javaFile.addMethod(JavaMethod.newMethod(PUBLIC, "void", "applyDataBinding",
compiler.getApplyDataBinding().toString() + JAXXCompiler.getLineSeparator() + "processDataBinding($binding);",
+ true,
new JavaArgument("String", "$binding")));
- javaFile.addMethod(JavaMethod.newMethod(Modifier.PUBLIC, "void", "removeDataBinding",
- compiler.getRemoveDataBinding().toString(), new JavaArgument("String", "$binding")));
+ javaFile.addMethod(JavaMethod.newMethod(PUBLIC, "void", "removeDataBinding",
+ compiler.getRemoveDataBinding().toString(), true, new JavaArgument("String", "$binding")));
javaFile.addMethod(createProcessDataBindingMethod(compiler, superclassIsJAXXObject));
@@ -315,19 +319,19 @@
int sizeLimit = 65000; // constant strings are limited to 64K, and I'm not brave enough to push right up to the limit
if (data.length() < sizeLimit) {
- return JavaField.newField(Modifier.PRIVATE | Modifier.STATIC, "java.lang.String", "$jaxxObjectDescriptor", TypeManager.getJavaCode(data));
+ return JavaField.newField(PRIVATE | STATIC, "java.lang.String", "$jaxxObjectDescriptor", false, compiler.getJavaCode(data));
} else {
StringBuffer initializer = new StringBuffer();
for (int i = 0; i < data.length(); i += sizeLimit) {
String name = "$jaxxObjectDescriptor" + i;
- javaFile.addField(new JavaField(Modifier.PRIVATE | Modifier.STATIC, "java.lang.String", name,
- TypeManager.getJavaCode(data.substring(i, Math.min(i + sizeLimit, data.length())))));
+ javaFile.addField(new JavaField(PRIVATE | STATIC, "java.lang.String", name, false,
+ compiler.getJavaCode(data.substring(i, Math.min(i + sizeLimit, data.length())))));
if (initializer.length() > 0) {
initializer.append(" + ");
}
initializer.append("String.valueOf(").append(name).append(")");
}
- return JavaField.newField(Modifier.PRIVATE | Modifier.STATIC, "java.lang.String", "$jaxxObjectDescriptor", initializer.toString());
+ return JavaField.newField(PRIVATE | STATIC | FINAL, "java.lang.String", "$jaxxObjectDescriptor", false, initializer.toString());
}
} catch (IOException e) {
throw new RuntimeException("Internal error: can't-happen error", e);
@@ -352,10 +356,10 @@
}
int modifiers = firePropertyChange != null ? firePropertyChange.getModifiers() : 0;
- if (Modifier.isPublic(modifiers)) {
+ if (isPublic(modifiers)) {
// we have all the support we need
}
- if (Modifier.isProtected(modifiers)) {
+ if (isProtected(modifiers)) {
// there is property change support but the firePropertyChange method is protected
javaFile.addMethod(FIRE_PROPERTY_CHANGE_METHOD);
} else {
@@ -382,7 +386,7 @@
if (listenerMethod.getParameterTypes().length != 1) {
throw new CompilerException("Expected event handler " + listenerMethod.getName() + " of class " + handler.getListenerClass() + " to have exactly one argument");
}
- javaFile.addMethod(JavaMethod.newMethod(Modifier.PUBLIC, "void", methodName, handler.getJavaCode(),
+ javaFile.addMethod(JavaMethod.newMethod(PUBLIC, "void", methodName, handler.getJavaCode(), false,
new JavaArgument(JAXXCompiler.getCanonicalName(listenerMethod.getParameterTypes()[0]), "event")));
}
}
@@ -392,59 +396,51 @@
protected JavaMethod createConstructor(JAXXCompiler compiler, String className, boolean superclassIsJAXXObject) throws CompilerException {
StringBuffer code = new StringBuffer();
String constructorParams = compiler.getRootObject().getConstructorParams();
+ String eol = JAXXCompiler.getLineSeparator();
if (constructorParams != null) {
- code.append(" super(").append(constructorParams).append(");").append(JAXXCompiler.getLineSeparator());
+ code.append(" super(").append(constructorParams).append(");").append(eol);
} else {
if (superclassIsJAXXObject) {
- code.append(" super();").append(JAXXCompiler.getLineSeparator());
+ code.append(" super();").append(eol);
}
}
code.append("$initialize();");
- code.append(JAXXCompiler.getLineSeparator());
- return JavaMethod.newMethod(Modifier.PUBLIC, null, className, code.toString());
+ code.append(eol);
+ return JavaMethod.newMethod(PUBLIC, null, className, code.toString(), false);
}
protected JavaMethod createConstructorWithInitialContext(JAXXCompiler compiler, String className, boolean superclassIsJAXXObject) throws CompilerException {
StringBuffer code = new StringBuffer();
String constructorParams = compiler.getRootObject().getConstructorParams();
+ String eol = JAXXCompiler.getLineSeparator();
if (constructorParams != null) {
- code.append(" super(").append(constructorParams).append(");").append(JAXXCompiler.getLineSeparator());
+ code.append(" super(").append(constructorParams).append(");").append(eol);
} else {
if (superclassIsJAXXObject) {
- code.append(" super(parentContext);").append(JAXXCompiler.getLineSeparator());
+ code.append(" super(parentContext);").append(eol);
}
}
if (!superclassIsJAXXObject) {
code.append(Util.class.getName() + ".initContext(this, parentContext);");
- code.append(JAXXCompiler.getLineSeparator());
-
-// code.append("if (parentContext instanceof jaxx.runtime.context.JAXXInitialContext) {");
-// code.append(JAXXCompiler.getLineSeparator());
-// code.append(" ((jaxx.runtime.context.JAXXInitialContext)parentContext).to(this);");
-// code.append(JAXXCompiler.getLineSeparator());
-// code.append("} else {");
-// code.append(JAXXCompiler.getLineSeparator());
-// code.append(" setContextValue(parentContext);");
-// code.append(JAXXCompiler.getLineSeparator());
-// code.append("}");
-// code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
}
code.append("$initialize();");
- code.append(JAXXCompiler.getLineSeparator());
- return JavaMethod.newMethod(Modifier.PUBLIC, null, className, code.toString(), new JavaArgument(JAXXContext.class.getName(), "parentContext"));
+ code.append(eol);
+ return JavaMethod.newMethod(PUBLIC, null, className, code.toString(), false, new JavaArgument(JAXXContext.class.getName(), "parentContext"));
}
public JavaMethod createInitializer(JAXXCompiler compiler) throws CompilerException {
+ String eol = JAXXCompiler.getLineSeparator();
StringBuffer code = new StringBuffer();
CompiledObject root = compiler.getRootObject();
code.append("if (allComponentsCreated || !contextInitialized) {");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
code.append(" return;");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
code.append("}");
- code.append(JAXXCompiler.getLineSeparator());
- code.append("$objectMap.put(").append(TypeManager.getJavaCode(root.getId())).append(", this);");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
+ code.append("$objectMap.put(").append(compiler.getJavaCode(root.getId())).append(", this);");
+ code.append(eol);
Iterator<CompiledObject> i = compiler.getObjectCreationOrder();
boolean lastWasMethodCall = false;
@@ -455,150 +451,83 @@
}
CompiledObjectDecorator decorator = object.getDecorator();
lastWasMethodCall = decorator.createInitializer(compiler, root, object, code, lastWasMethodCall);
- /*if (object != root && !object.isOverride()) {
- if (compiler.inlineCreation(object)) {
- if (lastWasMethodCall) {
- lastWasMethodCall = false;
- code.append(JAXXCompiler.getLineSeparator());
- }
- code.append(getCreationCode(compiler, object));
- code.append(JAXXCompiler.getLineSeparator());
- } else {
- code.append(object.getCreationMethodName()).append("();");
- code.append(JAXXCompiler.getLineSeparator());
- lastWasMethodCall = true;
- }
- }*/
}
root.getDecorator().createInitializer(compiler, root, root, code, lastWasMethodCall);
- /*String rootCode = root.getInitializationCode(compiler);
- if (rootCode != null && rootCode.length() > 0) {
- code.append(rootCode);
- code.append(JAXXCompiler.getLineSeparator());
- }*/
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
if (compiler.getInitializer().length() > 0) {
code.append(compiler.getInitializer());
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
}
code.append("$completeSetup();");
- code.append(JAXXCompiler.getLineSeparator());
- return JavaMethod.newMethod(Modifier.PRIVATE, "void", "$initialize", code.toString());
+ code.append(eol);
+ return JavaMethod.newMethod(PRIVATE, "void", "$initialize", code.toString(), false);
}
protected JavaMethod createCompleteSetupMethod(JAXXCompiler compiler, JavaFile javaFile, StringBuffer initDataBindings) {
StringBuffer code = new StringBuffer();
code.append("allComponentsCreated = true;");
- code.append(JAXXCompiler.getLineSeparator());
+ String eol = JAXXCompiler.getLineSeparator();
+ code.append(eol);
for (CompiledObject object : compiler.getObjects().values()) {
CompiledObjectDecorator decorator = object.getDecorator();
code.append(decorator.createCompleteSetupMethod(compiler, object, javaFile, initDataBindings));
-
- /*//TC - 20081017 only generate the method if not empty ?
- if (object.getId().startsWith("$")) {
- code.append(object.getAdditionCode()).append(JAXXCompiler.getLineSeparator());
- } else {
- String additionCode = object.getAdditionCode();
- if (additionCode.length() > 0) {
- code.append(object.getAdditionMethodName()).append("();").append(JAXXCompiler.getLineSeparator());
- additionCode = "if (!allComponentsCreated) {" + JAXXCompiler.getLineSeparator() + " return;" + JAXXCompiler.getLineSeparator() + "}" + JAXXCompiler.getLineSeparator() + additionCode;
- javaFile.addMethod(JavaMethod.newMethod(Modifier.PROTECTED, "void", object.getAdditionMethodName(), additionCode));
- }
- }*/
- //code.append(getLineSeparator());
}
code.append(initDataBindings);
if (compiler.getLateInitializer().length() > 0) {
code.append(compiler.getLateInitializer());
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
}
//TC-20090313 add an extra method after complete setup
MethodDescriptor method = compiler.getScriptMethod("$afterCompleteSetup");
if (method != null) {
- code.append("$afterCompleteSetup();").append(JAXXCompiler.getLineSeparator());
+ code.append("$afterCompleteSetup();").append(eol);
}
- return JavaMethod.newMethod(Modifier.PRIVATE, "void", "$completeSetup", code.toString());
+ return JavaMethod.newMethod(PRIVATE, "void", "$completeSetup", code.toString(), false);
}
protected JavaMethod createProcessDataBindingMethod(JAXXCompiler compiler, boolean superclassIsJAXXObject) {
StringBuffer code = new StringBuffer();
+ String eol = JAXXCompiler.getLineSeparator();
//boolean superclassIsJAXXObject = ClassDescriptorLoader.getClassDescriptor(JAXXObject.class).isAssignableFrom(compiler.getRootObject().getObjectClass());
// the force parameter forces the update to happen even if it is already in activeBindings. This
// is used on superclass invocations b/c by the time the call gets to the superclass, it is already
// marked active and would otherwise be skipped
if (compiler.getProcessDataBinding().length() > 0) {
code.append(" if (!$force && $activeBindings.contains($dest)) { ");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
code.append(" return;");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
code.append("}");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
code.append("$activeBindings.add($dest);");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
code.append("try {");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
if (compiler.getProcessDataBinding().length() > 0) {
code.append(compiler.getProcessDataBinding().toString());
//code.append(JAXXCompiler.getLineSeparator());
}
if (superclassIsJAXXObject) {
code.append(" else {");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
code.append(" super.processDataBinding($dest, true);");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
code.append(" }");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
}
code.append("} finally {");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
code.append(" $activeBindings.remove($dest);");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
code.append("}");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
} else if (superclassIsJAXXObject) {
code.append("super.processDataBinding($dest, true);");
- code.append(JAXXCompiler.getLineSeparator());
+ code.append(eol);
}
- return JavaMethod.newMethod(Modifier.PUBLIC, "void", "processDataBinding", code.toString(),
+ return JavaMethod.newMethod(PUBLIC, "void", "processDataBinding", code.toString(), superclassIsJAXXObject,
new JavaArgument("String", "$dest"), new JavaArgument("boolean", "$force"));
}
-
- /*---------------------------------------------------------------------------------*/
- /*-- Create methods code ----------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- /* protected String getCreationCode(JAXXCompiler compiler, CompiledObject object) throws CompilerException {
- if (object instanceof ScriptInitializer) {
- return object.getInitializationCode(compiler);
- }
- CompiledObjectDecorator decorator = object.getDecorator();
- String result = decorator.getCreationCode(compiler, object);
- return result;*/
- /*StringBuffer result = new StringBuffer();
- result.append(object.getId());
- result.append(" = ");
- if (object.isJavaBean() && object.getJavaBeanInitCode() != null) {
- result.append(object.getJavaBeanInitCode()).append(";");
- } else {
- String constructorParams = object.getConstructorParams();
- if (constructorParams != null) {
- //TC - 20081017 compiledObject can have generics
- result.append(" new ").append(JAXXCompiler.getCanonicalName(object)).append("(").append(constructorParams).append(");");
- //result.append("(").append(getCanonicalName(object.getObjectClass())).append(") new ").append(getCanonicalName(object.getObjectClass())).append("(").append(constructorParams).append(");");
- } else {
- //TC - 20081017 compiledObject can have generics
- result.append("new ").append(JAXXCompiler.getCanonicalName(object)).append("();");
- }
- }
- result.append(JAXXCompiler.getLineSeparator());
- String initCode = object.getInitializationCode(compiler);
- if (initCode != null && initCode.length() > 0) {
- result.append(initCode);
- }
- result.append("$objectMap.put(").append(TypeManager.getJavaCode(object.getId())).append(", ").append(object.getId()).append(");");
-
- return result.toString();*/
-// }
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/SwingGenerator.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/SwingGenerator.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/SwingGenerator.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,5 +1,8 @@
package jaxx.compiler.generators;
+import jaxx.compiler.io.JavaMethod;
+import jaxx.compiler.io.JavaArgument;
+import jaxx.compiler.io.JavaFile;
import jaxx.compiler.*;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.runtime.swing.Application;
@@ -19,8 +22,12 @@
//TODO : move this to jaxx-compiler-swing generator
if (ClassDescriptorLoader.getClassDescriptor(Application.class.getName()).isAssignableFrom(root.getObjectClass()) && !compiler.isMainDeclared()) {
// TODO: check for existing main method first
- javaFile.addMethod(JavaMethod.newMethod(Modifier.PUBLIC | Modifier.STATIC, "void", "main",
+ javaFile.addMethod(JavaMethod.newMethod(
+ Modifier.PUBLIC | Modifier.STATIC,
+ "void",
+ "main",
"SwingUtilities.invokeLater(new Runnable() { public void run() { new " + className + "().setVisible(true); } });",
+ false,
new JavaArgument("String[]", "arg")));
}
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/ValidatorGenerator.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/ValidatorGenerator.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/generators/ValidatorGenerator.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,12 +1,15 @@
package jaxx.compiler.generators;
+import jaxx.compiler.io.JavaMethod;
+import jaxx.compiler.io.JavaArgument;
+import jaxx.compiler.io.JavaField;
+import jaxx.compiler.io.JavaFile;
import jaxx.compiler.*;
import jaxx.compiler.CompiledObject.ChildRef;
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.tags.validator.BeanValidatorHandler;
import jaxx.compiler.tags.validator.BeanValidatorHandler.CompiledBeanValidator;
-import jaxx.compiler.types.TypeManager;
import java.util.List;
import jaxx.runtime.SwingUtil;
@@ -15,7 +18,7 @@
public class ValidatorGenerator implements Generator {
protected static final JavaField VALIDATOR_IDS_FIELD = JavaField.newField(java.lang.reflect.Modifier.PROTECTED,
- "java.util.List<String>", "validatorIds", "new ArrayList<String>()");
+ "java.util.List<String>", "validatorIds", true, "new ArrayList<String>()");
@Override
public void finalizeCompiler(CompiledObject root, JAXXCompiler compiler, JavaFile javaFile, String packageName, String className) {
@@ -39,19 +42,20 @@
}
}
}
+ String eol = JAXXCompiler.getLineSeparator();
// register validator
for (CompiledBeanValidator validator : BeanValidatorHandler.getValidators(compiler)) {
- String id = TypeManager.getJavaCode(validator.getId());
+ String id = compiler.getJavaCode(validator.getId());
compiler.appendLateInitializer("validatorIds.add(" + id + ");");
- compiler.appendLateInitializer(JAXXCompiler.getLineSeparator());
+ compiler.appendLateInitializer(eol);
compiler.appendLateInitializer("getValidator(" + id + ").installUIs();");
- compiler.appendLateInitializer(JAXXCompiler.getLineSeparator());
+ compiler.appendLateInitializer(eol);
compiler.appendLateInitializer("getValidator(" + id + ").reloadBean();");
//compiler.appendLateInitializer("getValidator(" + id + ").validate();");
- compiler.appendLateInitializer(JAXXCompiler.getLineSeparator());
+ compiler.appendLateInitializer(eol);
}
compiler.appendLateInitializer("validatorIds = java.util.Collections.unmodifiableList(validatorIds);");
- compiler.appendLateInitializer(JAXXCompiler.getLineSeparator());
+ compiler.appendLateInitializer(eol);
}
@Override
@@ -81,8 +85,12 @@
// implements JAXXValidator
javaFile.addField(VALIDATOR_IDS_FIELD);
- javaFile.addMethod(JavaMethod.newMethod(java.lang.reflect.Modifier.PUBLIC, validatorFQN + "<?>", "getValidator",
- "return (" + validatorFQN + ") (validatorIds.contains(validatorId) ? getObjectById(validatorId) : null);",
+ javaFile.addMethod(JavaMethod.newMethod(
+ java.lang.reflect.Modifier.PUBLIC,
+ validatorFQN + "<?>",
+ "getValidator",
+ "return (" + validatorFQN + "<?>) (validatorIds.contains(validatorId) ? getObjectById(validatorId) : null);",
+ true,
new JavaArgument("String", "validatorId")));
}
}
Copied: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaArgument.java (from rev 1582, branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaArgument.java)
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaArgument.java (rev 0)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaArgument.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2006 Ethan Nicholas. All rights reserved.
+ * Use is subject to license terms.
+ */
+package jaxx.compiler.io;
+
+/**
+ * Represents an argument to a <code>JavaMethod</code>.
+ *
+ * @see JavaMethod
+ */
+public class JavaArgument extends JavaElement {
+
+ private String type;
+ private boolean isFinal;
+
+ /**
+ * Creates a new <code>JavaArgument</code> with the specified name and type. For example, the method <code>main()</code>
+ * might have a <code>JavaArgument</code> with a name of <code>"arg"</code> and a type of <code>"java.lang.String[]"</code>.
+ *
+ * @param type the argument's type, as it would appear in Java source code
+ * @param name the argument's name
+ */
+ public JavaArgument(String type, String name) {
+ this(type, name, false);
+ }
+
+ /**
+ * Creates a new <code>JavaArgument</code> with the specified name, type, and finality. For example, the method <code>main()</code>
+ * might have a <code>JavaArgument</code> with a name of <code>"arg"</code> and a type of <code>"java.lang.String[]"</code>. The
+ * <code>isFinal</code> parameter allows the presence of the <code>final</code> keyword on the argument to be controlled.
+ *
+ * @param type the argument's type, as it would appear in Java source code
+ * @param name the argument's name
+ * @param isFinal <code>true</code> if the argument should be marked final
+ */
+ public JavaArgument(String type, String name, boolean isFinal) {
+ super(0, name);
+ this.type = type;
+ this.isFinal = isFinal;
+ }
+
+ /**
+ * Returns the argument's type as it would be represented in Java source code.
+ *
+ * @return the argument's type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Returns <code>true</code> if the <code>final</code> keyword should appear before the argument.
+ *
+ * @return <code>true</code> if the argument is final
+ */
+ public boolean isFinal() {
+ return isFinal;
+ }
+
+ /**
+ * Returns the Java source code for this argument.
+ *
+ * @return the Java source code for this argument
+ */
+ @Override
+ public String toString() {
+ String result = type + ' ' + getName();
+ return isFinal ? "final " + result : result;
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaArgument.java
___________________________________________________________________
Added: svn:mergeinfo
+
Added: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaElement.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaElement.java (rev 0)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaElement.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -0,0 +1,79 @@
+package jaxx.compiler.io;
+
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import jaxx.compiler.JAXXCompiler;
+
+/**
+ * Base Java element
+ * @author chemit
+ * @since 2.0.0
+ */
+public abstract class JavaElement {
+
+ private String lineSeparator;
+ private String name;
+ private int modifiers;
+
+ public JavaElement(int modifiers, String name) {
+ this.modifiers = modifiers;
+ this.name = name;
+ }
+
+ public final int getModifiers() {
+ return modifiers;
+ }
+
+ public final void setModifiers(int modifiers) {
+ this.modifiers = modifiers;
+ }
+
+ public final String getName() {
+ return name;
+ }
+
+ public final void setName(String className) {
+ this.name = className;
+ }
+
+ public final String getModifiersText() {
+ if (modifiers == 0) {
+ return "";
+ } else {
+ return Modifier.toString(modifiers) + ' ';
+ }
+ }
+
+ public final String getLineSeparator() {
+ if (lineSeparator == null) {
+ lineSeparator = JAXXCompiler.getLineSeparator();
+ }
+ return lineSeparator;
+ }
+
+ public static String addIndentation(String source, int indentation, String lineSeparator) {
+ return indent(source, indentation, false, lineSeparator);
+ }
+
+ public static String setIndentation(String source, int indentation, String lineSeparator) {
+ return indent(source, indentation, true, lineSeparator);
+ }
+
+ public static String indent(String source, int indentation, boolean trim, String lineSeparator) {
+ if (trim) {
+ source = source.trim();
+ }
+ char[] spaces = new char[indentation];
+ Arrays.fill(spaces, ' ');
+ StringBuffer result = new StringBuffer();
+ String[] lines = source.split(System.getProperty("line.separator") + "|\n");
+ for (int i = 0; i < lines.length; i++) {
+ if (i > 0) {
+ result.append(lineSeparator);
+ }
+ result.append(spaces);
+ result.append(trim ? lines[i].trim() : lines[i]);
+ }
+ return result.toString();
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaElement.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Copied: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaField.java (from rev 1582, branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaField.java)
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaField.java (rev 0)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaField.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2006 Ethan Nicholas. All rights reserved.
+ * Use is subject to license terms.
+ */
+package jaxx.compiler.io;
+
+import java.lang.reflect.Modifier;
+
+/**
+ * Represents a field in a Java source file being generated for output. <code>JavaFields</code> are created
+ * and added to a {@link JavaFile}, which can then output Java source code.
+ */
+public class JavaField extends JavaElement implements Comparable<JavaField> {
+
+ private String type;
+ private String initializer;
+ private boolean override;
+
+ /**
+ * Constructs a new <code>JavaField</code>. The <code>modifiers</code> parameter is a bit mask of the
+ * constants from {@link java.lang.reflect.Modifier}, and the <code>type</code> of the field should be
+ * represented as it would appear in Java source code.
+ *
+ * @param modifiers the modifier keywords that should appear as part of the field's declaration
+ * @param type the type of the field as it would appear in Java source code
+ * @param name the field's name
+ * @param override
+ */
+ public JavaField(int modifiers, String type, String name, boolean override) {
+ this(modifiers, type, name, override, null);
+ }
+
+ /**
+ * Constructs a new <code>JavaField</code>. The <code>modifiers</code> parameter is a bit mask of the
+ * constants from <code>java.lang.reflect.Modifier</code>, and the <code>type</code> of the field should be
+ * represented as it would appear in Java source code. The <code>initializer</code> is the initial
+ * value of the field as it would appear in Java source code, or <code>null</code> to leave it at the
+ * default value.
+ *
+ * @param modifiers the modifier keywords that should appear as part of the field's declaration
+ * @param type the type of the field as it would appear in Java source code
+ * @param name the field's name
+ * @param override
+ * @param initializer the initial value of the field, as it would appear in Java source code
+ */
+ public JavaField(int modifiers, String type, String name, boolean override, String initializer) {
+ super(modifiers, name);
+ this.type = type;
+ this.initializer = initializer;
+ this.override = override;
+ }
+
+ /**
+ * Returns the field's type, as it would be represented in Java source code.
+ *
+ * @return the field's type
+ */
+ public String getType() {
+ return type;
+ }
+
+ public boolean isOverride() {
+ return override;
+ }
+
+ public void setOverride(boolean override) {
+ this.override = override;
+ }
+
+ /**
+ * Returns the Java source code for this field.
+ *
+ * @return the Java source code for this field
+ */
+ @Override
+ public String toString() {
+ String eol = getLineSeparator();
+ StringBuffer result = new StringBuffer();
+ result.append(getModifiersText());
+ result.append(type).append(' ').append(getName());
+ if (initializer != null) {
+ result.append(" = ").append(initializer);
+ }
+ result.append(';').append(eol);
+ return result.toString();
+ }
+
+ @Override
+ public int compareTo(JavaField o) {
+ return JavaFieldComparator.COMPARATOR.compare(this, o);
+ }
+
+ public static JavaField newField(int modifiers, String returnType, String name, boolean override) {
+ return newField(modifiers, returnType, name, override, null);
+ }
+
+ public static JavaField newField(int modifiers, String returnType, String name, boolean override, String initializer) {
+ return new JavaField(modifiers, returnType, name, override, initializer);
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaField.java
___________________________________________________________________
Added: svn:mergeinfo
+
Added: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaFieldComparator.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaFieldComparator.java (rev 0)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaFieldComparator.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -0,0 +1,72 @@
+package jaxx.compiler.io;
+
+import java.lang.reflect.Modifier;
+import java.util.Comparator;
+
+class JavaFieldComparator implements Comparator<JavaField> {
+
+ static final JavaFieldComparator COMPARATOR = new JavaFieldComparator();
+
+ @Override
+ public int compare(JavaField o1, JavaField o2) {
+ int result;
+ if ((result = compareStatic(o1, o2)) != 0) {
+ return result;
+ }
+ // data sources must be on the last after all other fields
+ if ((result = compareDataSource(o1, o2)) != 0) {
+ return result;
+ }
+ // same static
+ if ((result = compareVisibility(o1, o2)) != 0) {
+ return result;
+ }
+ // same visibility, test name
+ return o1.getName().compareTo(o2.getName());
+ }
+
+ public int compareStatic(JavaField o1, JavaField o2) {
+ // first comparator modifiers : static always before none static
+ if (Modifier.isStatic(o1.getModifiers()) && !Modifier.isStatic(o2.getModifiers())) {
+ return -1;
+ }
+ if (!Modifier.isStatic(o1.getModifiers()) && Modifier.isStatic(o2.getModifiers())) {
+ return 1;
+ }
+ return 0;
+ }
+
+ public int compareDataSource(JavaField o1, JavaField o2) {
+ // first comparator modifiers : static always before none static
+ if (o1.getName().startsWith("$DataSource") && !o2.getName().startsWith("$DataSource")) {
+ return 1;
+ }
+ if (!o1.getName().startsWith("$DataSource") && o2.getName().startsWith("$DataSource")) {
+ return -1;
+ }
+ return 0;
+ }
+
+ public int compareVisibility(JavaField o1, JavaField o2) {
+ // first comparator modifiers : static always before none static
+ if (!Modifier.isPublic(o1.getModifiers()) && Modifier.isPublic(o2.getModifiers())) {
+ return 1;
+ }
+ if (Modifier.isPublic(o1.getModifiers()) && !Modifier.isPublic(o2.getModifiers())) {
+ return -1;
+ }
+ if (Modifier.isProtected(o1.getModifiers()) && !Modifier.isProtected(o2.getModifiers())) {
+ return -1;
+ }
+ if (!Modifier.isProtected(o1.getModifiers()) && Modifier.isProtected(o2.getModifiers())) {
+ return 1;
+ }
+ if (Modifier.isPrivate(o1.getModifiers()) && !Modifier.isPrivate(o2.getModifiers())) {
+ return -1;
+ }
+ if (!Modifier.isPrivate(o1.getModifiers()) && Modifier.isPrivate(o2.getModifiers())) {
+ return 1;
+ }
+ return 0;
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaFieldComparator.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Copied: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaFile.java (from rev 1582, branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaFile.java)
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaFile.java (rev 0)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaFile.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -0,0 +1,263 @@
+/*
+ * Copyright 2006 Ethan Nicholas. All rights reserved.
+ * Use is subject to license terms.
+ */
+package jaxx.compiler.io;
+
+import jaxx.compiler.io.JavaMethod.MethodOrder;
+
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map.Entry;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A Java source file being generated for output. Once the class is completely initialized, use the
+ * {@link #toString} method to generate source code for it.
+ */
+public class JavaFile extends JavaElement {
+
+ /**
+ * Logger
+ */
+ static private final Log log = LogFactory.getLog(JavaFile.class);
+ protected static final String GETTER_PATTERN = "return %1$s;";
+ protected static final String BOOLEAN_GETTER_PATTERN = "return %1$s !=null && %1$s;";
+ protected static final String SETTER_PATTERN = "%1$s oldValue = this.%2$s;\nthis.%2$s = newValue;\nfirePropertyChange(\"%2$s\", oldValue, newValue);";
+ private List<String> imports = new ArrayList<String>();
+ private List<JavaField> fields = new ArrayList<JavaField>();
+ private List<JavaMethod> methods = new ArrayList<JavaMethod>();
+ private List<JavaFile> innerClasses = new ArrayList<JavaFile>();
+ private String superClass;
+ private List<String> interfaces;
+ private StringBuffer rawBodyCode = new StringBuffer();
+ private boolean superclassIsJAXXObject;
+ private boolean abstractClass;
+ private String genericType;
+ private String superGenericType;
+
+ public JavaFile() {
+ super(0, "");
+ }
+
+ public JavaFile(int modifiers, String className, String superClass) {
+ this(modifiers, className, superClass, null);
+ }
+
+ public JavaFile(int modifiers, String className, String superClass, List<String> interfaces) {
+ super(modifiers, className);
+ this.superClass = superClass;
+ this.interfaces = interfaces;
+ }
+
+ public void addImport(String importString) {
+ imports.add(importString);
+ }
+
+ public void addImport(Class<?> importString) {
+ imports.add(importString.getName());
+ }
+
+ public String[] getImports() {
+ return imports.toArray(new String[imports.size()]);
+ }
+
+ public String getSuperClass() {
+ return superClass;
+ }
+
+ public void setSuperClass(String superClass) {
+ this.superClass = superClass;
+ }
+
+ public List<String> getInterfaces() {
+ if (interfaces == null) {
+ interfaces = new ArrayList<String>();
+ }
+ return interfaces;
+ }
+
+ public void setInterfaces(List<String> interfaces) {
+ this.interfaces = interfaces;
+ }
+
+ public void setGenericType(String genericType) {
+ this.genericType = genericType;
+ }
+
+ public void addMethod(JavaMethod method) {
+ methods.add(method);
+ }
+
+ public JavaMethod[] getMethods() {
+ return methods.toArray(new JavaMethod[methods.size()]);
+ }
+
+ public void addField(JavaField field) {
+ addField(field, false);
+ }
+
+ public void addField(JavaField field, boolean javaBean) {
+ addSimpleField(field);
+ String id = field.getName();
+ String capitalizedName = org.apache.commons.lang.StringUtils.capitalize(id);
+ // add getter file
+ String content = String.format(GETTER_PATTERN, id);
+ addMethod(new JavaMethod(
+ Modifier.isProtected(field.getModifiers()) ? Modifier.PUBLIC : Modifier.PROTECTED,
+ field.getType(), "get" + capitalizedName, null, null, content, field.isOverride()));
+
+ if (javaBean) {
+ // add full javabean support
+ if (Boolean.class.getName().equals(field.getType())) {
+ content = String.format(BOOLEAN_GETTER_PATTERN, id);
+ addMethod(new JavaMethod(Modifier.PUBLIC, field.getType(), "is" + capitalizedName, null, null, content, field.isOverride()));
+ }
+ content = String.format(SETTER_PATTERN, field.getType(), id);
+ JavaArgument arg = new JavaArgument(field.getType(), "newValue");
+ addMethod(new JavaMethod(Modifier.PUBLIC, "void", "set" + capitalizedName, new JavaArgument[]{arg}, null, content, field.isOverride()));
+ }
+ }
+
+ public void addSimpleField(JavaField field) {
+ fields.add(field);
+ }
+
+ public JavaField[] getFields() {
+ return fields.toArray(new JavaField[fields.size()]);
+ }
+
+ public void addBodyCode(String bodyCode) {
+ rawBodyCode.append(bodyCode);
+ }
+
+ @Override
+ public String toString() {
+ String eol = getLineSeparator();
+ StringBuffer result = new StringBuffer();
+ if (getName().indexOf(".") != -1) {
+ result.append("package ").append(getName().substring(0, getName().lastIndexOf("."))).append(";");
+ result.append(eol);
+ result.append(eol);
+ }
+
+ if (imports.size() > 0) {
+ for (String anImport : imports) {
+ result.append("import ");
+ result.append(anImport);
+ result.append(';');
+ result.append(eol);
+ }
+ result.append(eol);
+ }
+
+ result.append(getModifiersText());
+ if (abstractClass) {
+ result.append("abstract ");
+ }
+ result.append("class ");
+ result.append(getName().substring(getName().lastIndexOf(".") + 1));
+ if (genericType != null) {
+ result.append('<').append(genericType).append('>');
+ }
+ result.append(" extends ");
+ result.append(superClass);
+ if (superGenericType != null) {
+ result.append('<').append(superGenericType).append('>');
+ }
+ if (interfaces != null && !interfaces.isEmpty()) {
+ result.append(" implements ").append(interfaces.get(0));
+ for (int i = 1; i < interfaces.size(); i++) {
+ /*if (i > 0) {
+ result.append(", ");
+ }*/
+ result.append(", ").append(interfaces.get(i));
+ }
+ }
+ result.append(" {");
+ result.append(eol);
+ if (fields.size() > 0) {
+ java.util.Collections.sort(fields); // sort fields
+
+ for (JavaField field : fields) {
+ if (log.isDebugEnabled()) {
+ log.debug("generate field " + field);
+ }
+ result.append(addIndentation(field.toString(), 4, eol));
+ result.append(eol);
+ }
+
+ result.append(eol);
+ }
+
+ if (rawBodyCode.length() > 0) {
+ result.append(addIndentation("/* begin raw body code */\n", 4, eol));
+ String s = rawBodyCode.toString();
+ if (!s.startsWith(eol)) {
+ result.append(eol);
+ }
+ result.append(addIndentation(s, 4, eol));
+ result.append(eol);
+ result.append(addIndentation("/* end raw body code */", 4, eol));
+ result.append(eol);
+ }
+
+ for (JavaFile innerClass : innerClasses) {
+ result.append(addIndentation(innerClass.toString(), 4, eol));
+ result.append(eol).append(eol);
+ }
+
+ EnumMap<MethodOrder, List<JavaMethod>> map = JavaMethod.getSortedMethods(methods);
+ for (Entry<MethodOrder, List<JavaMethod>> entry : map.entrySet()) {
+ List<JavaMethod> list = entry.getValue();
+ if (!list.isEmpty()) {
+ result.append(addIndentation(entry.getKey().getHeader(), 4, eol));
+ result.append(eol).append(eol);
+ for (JavaMethod method : list) {
+ result.append(addIndentation(method.toString(), 4, eol));
+ result.append(eol).append(eol);
+ }
+ }
+ list.clear();
+ }
+ map.clear();
+ result.append("}");
+ return result.toString();
+ }
+
+ public void addInterface(String canonicalName) {
+ if (interfaces == null || !interfaces.contains(canonicalName)) {
+ getInterfaces().add(canonicalName);
+ }
+ }
+
+ public void addInterfaces(String[] canonicalNames) {
+ if (canonicalNames == null) {
+ return;
+ }
+ for (String canonicalName : canonicalNames) {
+ if (interfaces == null || !interfaces.contains(canonicalName)) {
+ getInterfaces().add(canonicalName);
+ }
+ }
+ }
+
+ public boolean isSuperclassIsJAXXObject() {
+ return superclassIsJAXXObject;
+ }
+
+ public void setSuperclassIsJAXXObject(boolean superclassIsJAXXObject) {
+ this.superclassIsJAXXObject = superclassIsJAXXObject;
+ }
+
+ public void setAbstractClass(boolean abstractClass) {
+ this.abstractClass = abstractClass;
+ }
+
+ public void setSuperGenericType(String superGenericType) {
+ this.superGenericType = superGenericType;
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaFile.java
___________________________________________________________________
Added: svn:mergeinfo
+
Copied: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaMethod.java (from rev 1582, branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/JavaMethod.java)
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaMethod.java (rev 0)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaMethod.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -0,0 +1,339 @@
+/*
+ * Copyright 2006 Ethan Nicholas. All rights reserved.
+ * Use is subject to license terms.
+ */
+package jaxx.compiler.io;
+
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Represents a method in a Java source file being generated for output. <code>JavaMethods</code> are created
+ * and added to a {@link JavaFile}, which can then output Java source code. In addition to normal methods, a
+ * <code>JavaMethod</code> can represent a constructor -- constructors should be named after their containing
+ * classes and have a return type of <code>null</code>.
+ */
+public class JavaMethod extends JavaElement implements Comparable<JavaMethod> {
+
+ private String returnType;
+ private JavaArgument[] arguments;
+ private String[] exceptions;
+ private String body;
+ private boolean override;
+// private StringBuffer bodyCode;
+
+ /**
+ * Constructs a new <code>JavaMethod</code> containing the specified body code. The <code>modifiers</code> parameter
+ * is a bit mask of the constants from {@link java.lang.reflect.Modifier}, and the <code>returnType</code> and
+ * <code>exceptions</code> of the method should be represented as they would appear in Java source code (<code>null</code>
+ * for a constructor). The method body is initially empty.
+ *
+ * @param modifiers the modifier keywords that should appear as part of the method's declaration
+ * @param returnType the return type of the method as it would appear in Java source code
+ * @param name the method's name
+ * @param arguments the method's arguments
+ * @param exceptions a list of exceptions the methods can throw, as they would be represented in Java source code
+ * @param bodyCode Java source code which should appear in the method body
+ * @param override flag with {@code true} value when the method overrides (or implements) a super class method
+ */
+ public JavaMethod(int modifiers, String returnType, String name, JavaArgument[] arguments, String[] exceptions, String bodyCode, boolean override) {
+ super(modifiers, name);
+ this.returnType = returnType;
+ this.override = override;
+ this.arguments = arguments;
+ this.exceptions = exceptions;
+ this.body = bodyCode == null ? "" : bodyCode;
+// this.bodyCode = new StringBuffer(bodyCode != null ? bodyCode : "");
+ }
+
+ /**
+ * Returns the method's return type, as it would be represented in Java source code.
+ *
+ * @return the method's return type
+ */
+ public String getReturnType() {
+ return returnType;
+ }
+
+ /**
+ * Returns a list of the method's arguments.
+ *
+ * @return the method's arguments
+ */
+ public JavaArgument[] getArguments() {
+ return arguments;
+ }
+
+ /**
+ * Returns a list of exceptions the method can throw.
+ *
+ * @return the method's exceptions
+ */
+ public String[] getExceptions() {
+ return exceptions;
+ }
+
+ public boolean isOverride() {
+ return override;
+ }
+
+ public void setOverride(boolean override) {
+ this.override = override;
+ }
+
+ @Override
+ public String toString() {
+ String eol = getLineSeparator();
+ StringBuffer result = new StringBuffer();
+ if (isOverride()) {
+ result.append("@Override").append(eol);
+ }
+ result.append(getModifiersText());
+ if (returnType != null) {
+ result.append(returnType);
+ result.append(' ');
+ }
+ result.append(getName());
+ result.append('(');
+ if (arguments != null) {
+ for (int i = 0; i < arguments.length; i++) {
+ if (i > 0) {
+ result.append(", ");
+ }
+ result.append(arguments[i].toString());
+ }
+ }
+ result.append(") {");
+ result.append(eol);
+ if (body != null) {
+ String formattedBodyCode = addIndentation(body.trim(), 4, eol);
+ if (formattedBodyCode.length() > 0) {
+ result.append(formattedBodyCode);
+ result.append(eol);
+ }
+ }
+ result.append("}");
+ return result.toString();
+ }
+
+ @Override
+ public int compareTo(JavaMethod o) {
+ return JavaMethodComparator.COMPARATOR.compare(this, o);
+ }
+
+ public static JavaMethod newMethod(int modifiers, String returnType, String name, String initializer, boolean override, String[] exceptions, JavaArgument... arguments) {
+ return new JavaMethod(modifiers, returnType, name, arguments, exceptions, initializer, override);
+ }
+
+ public static JavaMethod newMethod(int modifiers, String returnType, String name, String initializer, boolean override, JavaArgument... arguments) {
+ return newMethod(modifiers, returnType, name, initializer, override, new String[0], arguments);
+ }
+
+ public enum MethodOrder {
+
+ statics(Modifier.STATIC, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- Statics methods --------------------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+ },
+ constructors(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- Constructors -----------------------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ @Override
+ public boolean accept(JavaMethod method) {
+ return method.returnType == null;
+ }
+ },
+ JAXXObject(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- JAXXObject implementation ----------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ private List<String> methods = Arrays.asList("applyDataBinding", "firePropertyChange", "getObjectById", "get$objectMap", "processDataBinding", "removeDataBinding");
+
+ @Override
+ public boolean accept(JavaMethod method) {
+ return methods.contains(method.getName());
+ }
+ },
+ JAXXContext(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- JAXXContext implementation ---------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ private List<String> methods = Arrays.asList("getContextValue", "getDelegateContext", "getParentContainer", "removeContextValue", "setContextValue");
+
+ @Override
+ public boolean accept(JavaMethod method) {
+ return methods.contains(method.getName());
+ }
+ },
+ JAXXValidation(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- JAXXValidation implementation ------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ private List<String> methods = Arrays.asList("getValidator", "getValidatorIds");
+
+ @Override
+ public boolean accept(JavaMethod method) {
+ return methods.contains(method.getName());
+ }
+ },
+ events(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- Event methods ----------------------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ @Override
+ public boolean accept(JavaMethod method) {
+ return (method.getName().startsWith("do") && method.getName().indexOf("__") > -1);
+ }
+ },
+ publicGetters(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- public acessor methods -------------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ @Override
+ public boolean accept(JavaMethod method) {
+ return (method.getName().startsWith("get") || method.getName().startsWith("is"));
+ }
+ },
+ publicSetters(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- public mutator methods -------------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ @Override
+ public boolean accept(JavaMethod method) {
+ return (method.getName().startsWith("set"));
+ }
+ },
+ otherPublic(Modifier.PUBLIC, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- public mutator methods -------------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ @Override
+ public boolean accept(int mod) {
+ return super.accept(mod) && !Modifier.isStatic(mod);
+ }
+ },
+ protectedGetters(Modifier.PROTECTED, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- protected acessors methods ---------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ @Override
+ public boolean accept(JavaMethod method) {
+ return (method.getName().startsWith("get") || method.getName().startsWith("is"));
+ }
+ },
+ createMethod(Modifier.PROTECTED | Modifier.PRIVATE, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- ui creation methods ----------------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ @Override
+ public boolean accept(JavaMethod method) {
+ return method.getName().startsWith("create") || method.getName().startsWith("add") ||
+ method.getName().equals("$completeSetup") ||
+ method.getName().equals("$initialize");
+ }
+ },
+ protecteds(Modifier.PROTECTED, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- Other protected methods ------------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+ },
+ packageLocal(0, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- Package methods --------------------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+
+ @Override
+ public boolean accept(int mod) {
+ return !Modifier.isStatic(mod) && !Modifier.isPublic(mod) && !Modifier.isProtected(mod);
+ }
+ },
+ privates(Modifier.PRIVATE, "/*---------------------------------------------------------------------------------*/\n" +
+ "/*-- Private methods --------------------------------------------------------------*/\n" +
+ "/*---------------------------------------------------------------------------------*/") {
+ };
+ private final String header;
+ private int modifier;
+
+ MethodOrder(int modifier, String header) {
+ this.header = header;
+ this.modifier = modifier;
+ }
+
+ public String getHeader() {
+ return header;
+ }
+
+ public boolean accept(JavaMethod method) {
+ return true;
+ }
+
+ public boolean accept(int mod) {
+ return (mod & modifier) != 0;
+ }
+
+ public boolean accept(int mod, JavaMethod method) {
+ return accept(mod) && accept(method);
+ }
+
+ public static MethodOrder valueOf(JavaMethod method, int scope) {
+ for (MethodOrder o : values()) {
+ if (o.accept(scope, method)) {
+ return o;
+ }
+ }
+ throw new IllegalArgumentException("could not find a " + MethodOrder.class + " for method " + method);
+ }
+ }
+
+ public static EnumMap<MethodOrder, List<JavaMethod>> getSortedMethods(List<JavaMethod> methods) {
+
+ EnumMap<MethodOrder, List<JavaMethod>> result = new EnumMap<MethodOrder, List<JavaMethod>>(MethodOrder.class);
+ for (MethodOrder methodOrder : MethodOrder.values()) {
+ result.put(methodOrder, new ArrayList<JavaMethod>());
+ }
+
+ EnumSet<MethodOrder> allConstants = EnumSet.allOf(MethodOrder.class);
+ List<JavaMethod> allMethods = new ArrayList<JavaMethod>(methods);
+ int[] scopes = new int[]{Modifier.STATIC, Modifier.PUBLIC, Modifier.PROTECTED, Modifier.PRIVATE};
+ for (int scope : scopes) {
+ EnumSet<MethodOrder> constants = getMethodOrderScope(allConstants, scope);
+
+ Iterator<JavaMethod> itMethods = allMethods.iterator();
+ while (itMethods.hasNext()) {
+ JavaMethod method = itMethods.next();
+ for (MethodOrder constant : constants) {
+ if (constant.accept(method.getModifiers(), method)) {
+ result.get(constant).add(method);
+ itMethods.remove();
+ break;
+ }
+ }
+ }
+ constants.clear();
+ }
+
+ if (!allMethods.isEmpty()) {
+ throw new IllegalArgumentException("could not find a " + MethodOrder.class + " for method " + allMethods);
+ }
+
+ for (MethodOrder methodOrder : MethodOrder.values()) {
+ // sort methods
+ java.util.Collections.sort(result.get(methodOrder));
+ }
+ return result;
+ }
+
+ public static EnumSet<MethodOrder> getMethodOrderScope(EnumSet<MethodOrder> allConstants, int scope) {
+ EnumSet<MethodOrder> constants = EnumSet.noneOf(MethodOrder.class);
+ for (MethodOrder order : allConstants) {
+ if (order.accept(scope)) {
+ constants.add(order);
+ }
+ }
+ return constants;
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaMethod.java
___________________________________________________________________
Added: svn:mergeinfo
+
Added: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaMethodComparator.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaMethodComparator.java (rev 0)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaMethodComparator.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -0,0 +1,72 @@
+package jaxx.compiler.io;
+
+import java.lang.reflect.Modifier;
+import java.util.Comparator;
+
+/**
+ *
+ * @author chemit
+ * @since 2.0.0
+ */
+public class JavaMethodComparator implements Comparator<JavaMethod> {
+
+ static final JavaMethodComparator COMPARATOR = new JavaMethodComparator();
+
+ @Override
+ public int compare(JavaMethod o1, JavaMethod o2) {
+
+ /*int result;
+ if ((result = compareStatic(o1, o2)) != 0) {
+ return result;
+ }
+ if ((result = compareConstructor(o1, o2)) != 0) {
+ return result;
+ }
+ if ((result = compareVisibility(o1, o2)) != 0) {
+ return result;
+ }*/
+ return o1.getName().compareTo(o2.getName());
+ }
+
+ public int compareStatic(JavaMethod o1, JavaMethod o2) {
+ if (Modifier.isStatic(o1.getModifiers()) && !Modifier.isStatic(o2.getModifiers())) {
+ return -1;
+ }
+ if (!Modifier.isStatic(o1.getModifiers()) && Modifier.isStatic(o2.getModifiers())) {
+ return 1;
+ }
+ return 0;
+ }
+
+ public int compareConstructor(JavaMethod o1, JavaMethod o2) {
+ if (o1.getReturnType() == null && o2.getReturnType() != null) {
+ return -1;
+ }
+ if (o1.getReturnType() != null && o2.getReturnType() == null) {
+ return 1;
+ }
+ return 0;
+ }
+
+ public int compareVisibility(JavaMethod o1, JavaMethod o2) {
+ if (Modifier.isPublic(o1.getModifiers()) && !Modifier.isPublic(o2.getModifiers())) {
+ return -1;
+ }
+ if (!Modifier.isPublic(o1.getModifiers()) && Modifier.isPublic(o2.getModifiers())) {
+ return 1;
+ }
+ if (Modifier.isProtected(o1.getModifiers()) && !Modifier.isProtected(o2.getModifiers())) {
+ return -1;
+ }
+ if (!Modifier.isProtected(o1.getModifiers()) && Modifier.isProtected(o2.getModifiers())) {
+ return 1;
+ }
+ if (Modifier.isPrivate(o1.getModifiers()) && !Modifier.isPrivate(o2.getModifiers())) {
+ return -1;
+ }
+ if (!Modifier.isPrivate(o1.getModifiers()) && Modifier.isPrivate(o2.getModifiers())) {
+ return 1;
+ }
+ return 0;
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/io/JavaMethodComparator.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorLoader.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorLoader.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorLoader.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -2,7 +2,7 @@
import jaxx.compiler.CompilerException;
import jaxx.compiler.JAXXCompiler;
-import jaxx.compiler.JAXXCompilerLaunchor;
+import jaxx.compiler.JAXXEngine;
import jaxx.compiler.SymbolTable;
import jaxx.runtime.JAXXObject;
import jaxx.runtime.JAXXObjectDescriptor;
@@ -50,7 +50,7 @@
}
// if (result == null) {
- if (JAXXCompilerLaunchor.isRegistred() && JAXXCompilerLaunchor.get().getSymbolTable(className) != null) {
+ if (JAXXEngine.isRegistred() && JAXXEngine.get().getSymbolTable(className) != null) {
result = createClassDescriptorFromSymbolTable(className, classLoader);
} else {
if (classLoader == null) {
@@ -90,7 +90,7 @@
}
}
- if (jaxxLastModified != -1 && JAXXCompilerLaunchor.isRegistred() && JAXXCompilerLaunchor.get().getSymbolTable(className) == null) {
+ if (jaxxLastModified != -1 && JAXXEngine.isRegistred() && JAXXEngine.get().getSymbolTable(className) == null) {
jaxxLastModified = -1; // file has been modified, but wasn't included in this
}
// compilation set so we don't have a symbol table
@@ -303,8 +303,8 @@
}
private static ClassDescriptor createClassDescriptorFromSymbolTable(String className, ClassLoader classLoader) throws ClassNotFoundException {
- final JAXXCompiler compiler = JAXXCompilerLaunchor.get().getJAXXCompiler(className);
- final SymbolTable symbolTable = JAXXCompilerLaunchor.get().getSymbolTable(className);
+ final JAXXCompiler compiler = JAXXEngine.get().getJAXXCompiler(className);
+ final SymbolTable symbolTable = JAXXEngine.get().getSymbolTable(className);
if (symbolTable == null) {
throw new CompilerException("Internal error: no symbol table was generated for class '" + className + "'");
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/reflect/JavaFileParser.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/reflect/JavaFileParser.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/reflect/JavaFileParser.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -2,7 +2,7 @@
import jaxx.compiler.CompilerException;
import jaxx.compiler.JAXXCompiler;
-import jaxx.compiler.JAXXCompilerLaunchor;
+import jaxx.compiler.JAXXEngine;
import jaxx.compiler.parser.java.JavaParser;
import jaxx.compiler.parser.java.JavaParserTreeConstants;
import jaxx.compiler.parser.java.ParseException;
@@ -31,7 +31,7 @@
private List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>();
private JavaFileParser(ClassLoader classLoader) {
- compiler = JAXXCompilerLaunchor.createDummyCompiler(classLoader);
+ compiler = JAXXEngine.createDummyCompiler(classLoader);
}
public static ClassDescriptor parseJavaFile(String displayName, Reader src, ClassLoader classLoader) throws ClassNotFoundException {
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/spi/DefaultInitializer.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/spi/DefaultInitializer.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/spi/DefaultInitializer.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -4,10 +4,7 @@
*/
package jaxx.compiler.spi;
-import java.awt.Color;
import java.awt.Component;
-import java.awt.GridBagConstraints;
-import java.awt.Insets;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComboBox;
@@ -35,18 +32,11 @@
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.JWindow;
-import javax.swing.KeyStroke;
import javax.swing.text.JTextComponent;
import jaxx.compiler.JAXXCompiler;
import jaxx.compiler.beans.BeanInfoUtil;
-import jaxx.compiler.decorators.BoxedCompiledObjectDecorator;
-import jaxx.compiler.decorators.CompiledObjectDecorator;
-import jaxx.compiler.decorators.CompiledObjectDecoratorManager;
-import jaxx.compiler.decorators.DefaultCompiledObjectDecorator;
-import jaxx.compiler.decorators.HelpRootCompiledObjectDecorator;
-
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.tags.DefaultComponentHandler;
@@ -87,14 +77,7 @@
import jaxx.compiler.tags.validator.ExcludeFieldValidatorHandler;
import jaxx.compiler.tags.validator.FieldValidatorHandler;
-import jaxx.compiler.types.ColorConverter;
-import jaxx.compiler.types.GridBagConstraintsConverter;
-import jaxx.compiler.types.InsetsConverter;
-import jaxx.compiler.types.KeyStrokeConverter;
-import jaxx.compiler.types.PrimitiveConverter;
-import jaxx.compiler.types.TypeConverter;
-import jaxx.compiler.types.TypeManager;
import jaxx.runtime.swing.Application;
import jaxx.runtime.swing.JAXXButtonGroup;
import jaxx.runtime.swing.JAXXComboBox;
@@ -125,16 +108,7 @@
JTextField.class,
JTextPane.class);
-
//
- // Register decorators
- //
-
- registerDecorator("default", DefaultCompiledObjectDecorator.class);
- registerDecorator("boxed", BoxedCompiledObjectDecorator.class);
- registerDecorator("help", HelpRootCompiledObjectDecorator.class);
-
- //
// Register tags
//
@@ -209,39 +183,8 @@
registerBean(Table.class, TableHandler.class);
registerBean(JAXXTab.class, JAXXTabHandler.class);
-
registerBean(SwingValidator.class, BeanValidatorHandler.class);
-
-
- //
- // Register converters
- //
-
- PrimitiveConverter primitiveConverter = new PrimitiveConverter();
- registerTypeConverter(boolean.class, primitiveConverter);
- registerTypeConverter(Boolean.class, primitiveConverter);
- registerTypeConverter(byte.class, primitiveConverter);
- registerTypeConverter(Byte.class, primitiveConverter);
- registerTypeConverter(short.class, primitiveConverter);
- registerTypeConverter(Short.class, primitiveConverter);
- registerTypeConverter(int.class, primitiveConverter);
- registerTypeConverter(Integer.class, primitiveConverter);
- registerTypeConverter(long.class, primitiveConverter);
- registerTypeConverter(Long.class, primitiveConverter);
- registerTypeConverter(float.class, primitiveConverter);
- registerTypeConverter(Float.class, primitiveConverter);
- registerTypeConverter(double.class, primitiveConverter);
- registerTypeConverter(Double.class, primitiveConverter);
- registerTypeConverter(char.class, primitiveConverter);
- registerTypeConverter(Character.class, primitiveConverter);
- registerTypeConverter(String.class, primitiveConverter);
-
- registerTypeConverter(Color.class, new ColorConverter());
- registerTypeConverter(GridBagConstraints.class, new GridBagConstraintsConverter());
- registerTypeConverter(Insets.class, new InsetsConverter());
- registerTypeConverter(KeyStroke.class, new KeyStrokeConverter());
-
}
protected void registerBean(Class<?> beanClass, Class<? extends TagHandler> handlerClass) {
@@ -252,16 +195,6 @@
TagManager.registerTag(namespace, tagName, handler);
}
- protected void registerDecorator(String name, Class<? extends CompiledObjectDecorator> decoratorClass) {
-
- CompiledObjectDecoratorManager.registerDecorator(name, decoratorClass);
- }
-
- protected void registerTypeConverter(Class<?> converterType, TypeConverter converter) {
-
- TypeManager.registerTypeConverter(converterType, converter);
- }
-
protected void registerDefaultNamespace(String namespace, Class<?>... beanClass) {
for (Class<?> c : beanClass) {
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -8,15 +8,14 @@
import jaxx.compiler.UnsupportedAttributeException;
import jaxx.compiler.CompiledObject;
import jaxx.compiler.JAXXCompiler;
-import jaxx.compiler.JavaArgument;
-import jaxx.compiler.JavaMethod;
+import jaxx.compiler.io.JavaArgument;
+import jaxx.compiler.io.JavaMethod;
import jaxx.compiler.StylesheetHelper;
import jaxx.compiler.beans.JAXXBeanInfo;
import jaxx.compiler.beans.JAXXEventSetDescriptor;
import jaxx.compiler.beans.JAXXIntrospector;
import jaxx.compiler.beans.JAXXPropertyDescriptor;
import jaxx.compiler.decorators.CompiledObjectDecorator;
-import jaxx.compiler.decorators.CompiledObjectDecoratorManager;
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.reflect.FieldDescriptor;
@@ -140,8 +139,6 @@
}
/**
- * Returns
- *
* @return the class which this <code>DefaultObjectHandler</code> supports.
*/
public ClassDescriptor getBeanClass() {
@@ -286,11 +283,11 @@
if (!methodExists) {
compiler.addMethodToJavaFile(new JavaMethod(Modifier.PUBLIC, "void", methodName,
new JavaArgument[]{new JavaArgument(JAXXCompiler.getCanonicalName(eventClass), "event")}, null,
- propertyChangeListenerCode + ".propertyChange(null);"));
+ propertyChangeListenerCode + ".propertyChange(null);", false));
}
String code = objectCode + (eventInfo.modelName != null ? ".get" + org.apache.commons.lang.StringUtils.capitalize(eventInfo.modelName) + "()" : "");
result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator());
- result.append(code).append('.').append(eventInfo.addMethod).append("((").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(") jaxx.runtime.Util.getEventListener(").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));\n");
+ result.append(code).append('.').append(eventInfo.addMethod).append("((").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(") jaxx.runtime.Util.getEventListener(").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(compiler.getJavaCode(methodName)).append("));\n");
if (eventInfo.modelName != null) {
result.append(getAddMemberListenerCode(objectCode, dataBinding, "get" + org.apache.commons.lang.StringUtils.capitalize(eventInfo.modelName),
"jaxx.runtime.Util.getDataBindingUpdateListener(this , \"" + dataBinding + "\")",
@@ -340,13 +337,13 @@
ClassDescriptor eventClass = getEventClass(eventInfo.listenerClass);
compiler.addMethodToJavaFile(new JavaMethod(Modifier.PUBLIC, "void", methodName,
new JavaArgument[]{new JavaArgument(JAXXCompiler.getCanonicalName(eventClass), "event")}, null,
- propertyChangeListenerCode + ".propertyChange(null);"));
+ propertyChangeListenerCode + ".propertyChange(null);", false));
}
try {
String modelMemberName = eventInfo.modelName != null ? "get" + org.apache.commons.lang.StringUtils.capitalize(eventInfo.modelName) : null;
String modelClassName = modelMemberName != null ? getBeanClass().getMethodDescriptor(modelMemberName).getReturnType().getName() : JAXXCompiler.getCanonicalName(getBeanClass());
String code = objectCode + (eventInfo.modelName != null ? "." + modelMemberName + "()" : "");
- result.append("((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\")).").append(eventInfo.removeMethod).append("((").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(") jaxx.runtime.Util.getEventListener(").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));\n");
+ result.append("((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\")).").append(eventInfo.removeMethod).append("((").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(") jaxx.runtime.Util.getEventListener(").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(compiler.getJavaCode(methodName)).append("));\n");
if (eventInfo.modelName != null) {
result.append(getRemoveMemberListenerCode(objectCode, dataBinding, "get" + org.apache.commons.lang.StringUtils.capitalize(eventInfo.modelName),
"jaxx.runtime.Util.getDataBindingUpdateListener(this, \"" + dataBinding + "\")",
@@ -690,7 +687,7 @@
if (name.equals("decorator")) {
if (!value.isEmpty()) {
- CompiledObjectDecorator decorator = CompiledObjectDecoratorManager.getDecorator(value);
+ CompiledObjectDecorator decorator = compiler.getEngine().getDecorator(value);
object.setDecorator(decorator);
}
continue;
@@ -751,7 +748,7 @@
try {
Class<?> typeClass = type != null ? ClassDescriptorLoader.getClass(type.getName(), type.getClassLoader()) : null;
Object value = convertFromString(propertyName, stringValue, typeClass);
- return getSetPropertyCode(object.getJavaCode(), propertyName, TypeManager.getJavaCode(value), compiler);
+ return getSetPropertyCode(object.getJavaCode(), propertyName, compiler.getJavaCode(value), compiler);
} catch (NumberFormatException e) {
compiler.reportError("could not convert literal string '" + stringValue + "' to type " + type.getName());
} catch (IllegalArgumentException e) {
@@ -778,7 +775,7 @@
// check for data binding & remove if found
JAXXObjectDescriptor jaxxObjectDescriptor = object.getObjectClass().getJAXXObjectDescriptor();
ComponentDescriptor root = jaxxObjectDescriptor.getComponentDescriptors()[0];
- object.appendInitializationCode(object.getJavaCode() + ".removeDataBinding(" + TypeManager.getJavaCode(root.getId() + "." + propertyName) + ");" + JAXXCompiler.getLineSeparator());
+ object.appendInitializationCode(object.getJavaCode() + ".removeDataBinding(" + compiler.getJavaCode(root.getId() + "." + propertyName) + ");" + JAXXCompiler.getLineSeparator());
}
object.addProperty(propertyName, stringValue);
ClassDescriptor type = getPropertyType(object, propertyName, compiler);
@@ -845,7 +842,7 @@
String id = isRoot ? object.getId() + ' ' + descriptor.getId() : "( " + object.getId() + " ) " + descriptor.getId();
CompiledObject child = new CompiledObject(id,
"((" + JAXXCompiler.getCanonicalName(classDescriptor) + ") " +
- object.getJavaCode() + ".getObjectById(" + TypeManager.getJavaCode(descriptor.getId()) + "))",
+ object.getJavaCode() + ".getObjectById(" + compiler.getJavaCode(descriptor.getId()) + "))",
classDescriptor,
compiler,
true);
@@ -983,7 +980,7 @@
* @throws CompilerException if a compilation error occurs
*/
public void setProperty(CompiledObject object, String name, Object value, JAXXCompiler compiler) {
- object.appendInitializationCode(getSetPropertyCode(object.getJavaCodeForProperty(name), name, TypeManager.getJavaCode(value), compiler));
+ object.appendInitializationCode(getSetPropertyCode(object.getJavaCodeForProperty(name), name, compiler.getJavaCode(value), compiler));
}
/**
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/TagManager.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/TagManager.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/TagManager.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -5,7 +5,6 @@
package jaxx.compiler.tags;
import jaxx.compiler.*;
-import jaxx.compiler.decorators.CompiledObjectDecoratorManager;
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import org.apache.commons.logging.Log;
@@ -85,8 +84,7 @@
registeredBeans.clear();
registeredTags.clear();
defaultNamespaces.clear();
- CompiledObjectDecoratorManager.reset();
- JAXXCompilerLaunchor.loadLibraries(verbose);
+ JAXXEngine.loadLibraries(verbose);
}
/**
@@ -233,22 +231,24 @@
}
boolean found = false;
+ ClassLoader classLoader = compiler.getClassLoader();
try {
- Class.forName(className, true, compiler.getClassLoader());
+ Class.forName(className, true,classLoader);
found = true;
} catch (ClassNotFoundException e) {
// ignore ?
- } catch (NoClassDefFoundError e) { // we get this instead of ClassNotFoundException on case-insensitive file systems when
+ } catch (NoClassDefFoundError e) {
+ // we obtain this instead of ClassNotFoundException on case-insensitive file systems when
// looking up a class with the wrong case
}
if (!found) { // couldn't find .class, check for .java
- URL javaURL = compiler.getClassLoader().getResource(className.replace('.', '/') + ".java");
+ URL javaURL = classLoader.getResource(className.replace('.', '/') + ".java");
found = javaURL != null;
}
if (!found) { // couldn't find .java, check for .jaxx
- URL jaxxURL = compiler.getClassLoader().getResource(className.replace('.', '/') + ".jaxx");
+ URL jaxxURL = classLoader.getResource(className.replace('.', '/') + ".jaxx");
found = jaxxURL != null;
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -25,7 +25,7 @@
@Override
public void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler) throws CompilerException {
if (propertyName.equals("lookAndFeel") && stringValue != null && !stringValue.trim().startsWith("{")) {
- compiler.appendBodyCode("{ " + object.getJavaCode() + ".setLookAndFeel(" + TypeManager.getJavaCode(stringValue) + "); }" + JAXXCompiler.getLineSeparator());
+ compiler.appendBodyCode("{ " + object.getJavaCode() + ".setLookAndFeel(" + compiler.getJavaCode(stringValue) + "); }" + JAXXCompiler.getLineSeparator());
} else {
super.setAttribute(object, propertyName, stringValue, inline, compiler);
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXComboBoxHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXComboBoxHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXComboBoxHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -10,7 +10,6 @@
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.tags.DefaultComponentHandler;
-import jaxx.compiler.types.TypeManager;
import jaxx.runtime.swing.JAXXComboBox;
import jaxx.runtime.swing.Item;
import org.w3c.dom.Element;
@@ -49,7 +48,7 @@
for (Item item : items) {
String id = item.getId();
CompiledObject compiledItem = new CompiledObject(id, ClassDescriptorLoader.getClassDescriptor(Item.class), compiler);
- compiledItem.setConstructorParams(TypeManager.getJavaCode(id) + ", " + TypeManager.getJavaCode(item.getLabel()) + ", " + TypeManager.getJavaCode(item.getValue()) + ", " + item.isSelected());
+ compiledItem.setConstructorParams(compiler.getJavaCode(id) + ", " + compiler.getJavaCode(item.getLabel()) + ", " + compiler.getJavaCode(item.getValue()) + ", " + item.isSelected());
compiler.registerCompiledObject(compiledItem);
list.appendAdditionCode(listName + ".add(" + id + ");");
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXListHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXListHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXListHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -10,7 +10,6 @@
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.tags.DefaultComponentHandler;
-import jaxx.compiler.types.TypeManager;
import jaxx.runtime.swing.JAXXList;
import jaxx.runtime.swing.Item;
import org.w3c.dom.Element;
@@ -52,7 +51,7 @@
for (Item item : items) {
String id = item.getId();
CompiledObject compiledItem = new CompiledObject(id, ClassDescriptorLoader.getClassDescriptor(Item.class), compiler);
- compiledItem.setConstructorParams(TypeManager.getJavaCode(id) + ", " + TypeManager.getJavaCode(item.getLabel()) + ", " + TypeManager.getJavaCode(item.getValue()) + ", " + item.isSelected());
+ compiledItem.setConstructorParams(compiler.getJavaCode(id) + ", " + compiler.getJavaCode(item.getLabel()) + ", " + compiler.getJavaCode(item.getValue()) + ", " + item.isSelected());
compiler.registerCompiledObject(compiledItem);
list.appendAdditionCode(listName + ".add(" + id + ");");
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXTreeHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXTreeHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JAXXTreeHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -10,7 +10,6 @@
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.tags.DefaultComponentHandler;
-import jaxx.compiler.types.TypeManager;
import jaxx.runtime.swing.Item;
import jaxx.runtime.swing.JAXXTree;
import org.w3c.dom.Element;
@@ -45,7 +44,7 @@
for (Item item : items) {
String id = item.getId();
CompiledObject compiledItem = new CompiledObject(id, ClassDescriptorLoader.getClassDescriptor(Item.class), compiler);
- compiledItem.setConstructorParams(TypeManager.getJavaCode(id) + ", " + TypeManager.getJavaCode(item.getLabel()) + ", " + TypeManager.getJavaCode(item.getValue()) + ", " + item.isSelected());
+ compiledItem.setConstructorParams(compiler.getJavaCode(id) + ", " + compiler.getJavaCode(item.getLabel()) + ", " + compiler.getJavaCode(item.getValue()) + ", " + item.isSelected());
compiler.registerCompiledObject(compiledItem);
tree.appendAdditionCode(addMethod + "(" + id + ");");
createItems(tree, item.getChildren(), id + ".addChild", compiler);
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -11,7 +11,6 @@
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.tags.DefaultComponentHandler;
-import jaxx.compiler.types.TypeManager;
import jaxx.runtime.swing.JAXXButtonGroup;
import javax.swing.AbstractButton;
@@ -53,7 +52,7 @@
@Override
public void setProperty(CompiledObject object, String name, Object value, JAXXCompiler compiler) {
if (name.equals(BUTTON_GROUP_PROPERTY)) {
- object.appendAdditionCode(getSetPropertyCode(object.getJavaCode(), name, TypeManager.getJavaCode(value), compiler));
+ object.appendAdditionCode(getSetPropertyCode(object.getJavaCode(), name, compiler.getJavaCode(value), compiler));
} else {
super.setProperty(object, name, value, compiler);
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -11,7 +11,6 @@
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.tags.DefaultComponentHandler;
-import jaxx.compiler.types.TypeManager;
import jaxx.runtime.swing.TabInfo;
import javax.swing.Icon;
@@ -61,10 +60,10 @@
if (I18nHelper.isI18nAttribute("title")) {
if (!title.startsWith("_(\"")) {
// we did not have the invocation code, add it
- title = I18nHelper.addI18nInvocation(getId(), "title", TypeManager.getJavaCode(title), compiler);
+ title = I18nHelper.addI18nInvocation(getId(), "title", compiler.getJavaCode(title), compiler);
}
} else {
- title = TypeManager.getJavaCode(title);
+ title = compiler.getJavaCode(title);
}
appendAdditionCode(getId() + ".setTitleAt(" + tabIndex + ", " + title + ");");
}
@@ -74,10 +73,10 @@
if (I18nHelper.isI18nAttribute("toolTipText")) {
if (!toolTipText.startsWith("_(\"")) {
// we did not have the invocation code, add it
- toolTipText = I18nHelper.addI18nInvocation(getId(), "toolTipText", TypeManager.getJavaCode(toolTipText), compiler);
+ toolTipText = I18nHelper.addI18nInvocation(getId(), "toolTipText", compiler.getJavaCode(toolTipText), compiler);
}
} else {
- toolTipText = TypeManager.getJavaCode(toolTipText);
+ toolTipText = compiler.getJavaCode(toolTipText);
}
appendAdditionCode(getId() + ".setToolTipTextAt(" + tabIndex + ", " + toolTipText + ");");
}
@@ -89,12 +88,12 @@
Color foreground = tabInfo.getForeground();
if (foreground != null) {
- appendAdditionCode(getId() + ".setForegroundAt(" + tabIndex + ", " + TypeManager.getJavaCode(foreground) + ");");
+ appendAdditionCode(getId() + ".setForegroundAt(" + tabIndex + ", " + compiler.getJavaCode(foreground) + ");");
}
Color background = tabInfo.getBackground();
if (background != null) {
- appendAdditionCode(getId() + ".setBackgroundAt(" + tabIndex + ", " + TypeManager.getJavaCode(background) + ");");
+ appendAdditionCode(getId() + ".setBackgroundAt(" + tabIndex + ", " + compiler.getJavaCode(background) + ");");
}
int mnemonic = tabInfo.getMnemonic();
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TabHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TabHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TabHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -10,7 +10,6 @@
import jaxx.compiler.JAXXCompiler;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.tags.TagHandler;
-import jaxx.compiler.types.TypeManager;
import jaxx.runtime.swing.TabInfo;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
@@ -64,7 +63,7 @@
return;
}
- String valueCode = TypeManager.getJavaCode(value);
+ String valueCode = compiler.getJavaCode(value);
// add i18n support
if (I18nHelper.isI18nableAttribute(name, compiler)) {
@@ -80,33 +79,33 @@
compiledTabInfo.appendInitializationCode(id + ".setToolTipText(" + valueCode + ");");
//compiledTabInfo.appendInitializationCode(id + ".setToolTipText(" + TypeManager.getJavaCode(value) + ");");
} else if (name.equals("icon")) {
- Icon icon = (Icon) TypeManager.convertFromString(value, Icon.class);
+ Icon icon = (Icon) compiler.convertFromString(value, Icon.class);
tabInfo.setIcon(icon);
- compiledTabInfo.appendInitializationCode(id + ".setIcon(" + TypeManager.getJavaCode(icon) + ");");
+ compiledTabInfo.appendInitializationCode(id + ".setIcon(" + compiler.getJavaCode(icon) + ");");
} else if (name.equals("enabled")) {
- boolean enabled = (Boolean) TypeManager.convertFromString(value, Boolean.class);
+ boolean enabled = (Boolean) compiler.convertFromString(value, Boolean.class);
tabInfo.setEnabled(enabled);
compiledTabInfo.appendInitializationCode(id + ".setEnabled(" + enabled + ");");
} else if (name.equals("disabledIcon")) {
- Icon disabledIcon = (Icon) TypeManager.convertFromString(value, Icon.class);
+ Icon disabledIcon = (Icon) compiler.convertFromString(value, Icon.class);
tabInfo.setDisabledIcon(disabledIcon);
- compiledTabInfo.appendInitializationCode(id + ".setDisabledIcon(" + TypeManager.getJavaCode(disabledIcon) + ");");
+ compiledTabInfo.appendInitializationCode(id + ".setDisabledIcon(" + compiler.getJavaCode(disabledIcon) + ");");
} else if (name.equals("mnemonic")) {
- int mnemonic = (Character) TypeManager.convertFromString(value, char.class);
+ int mnemonic = (Character) compiler.convertFromString(value, char.class);
tabInfo.setMnemonic(mnemonic);
compiledTabInfo.appendInitializationCode(id + ".setMnemonic(" + mnemonic + ");");
} else if (name.equals("displayedMnemonicIndex")) {
- int displayedMnemonicIndex = (Integer) TypeManager.convertFromString(value, int.class);
+ int displayedMnemonicIndex = (Integer) compiler.convertFromString(value, int.class);
tabInfo.setDisplayedMnemonicIndex(displayedMnemonicIndex);
compiledTabInfo.appendInitializationCode(id + ".setDisplayedMnemonicIndex(" + displayedMnemonicIndex + ");");
} else if (name.equals("foreground")) {
- Color foreground = (Color) TypeManager.convertFromString(value, Color.class);
+ Color foreground = (Color) compiler.convertFromString(value, Color.class);
tabInfo.setForeground(foreground);
- compiledTabInfo.appendInitializationCode(id + ".setForeground(" + TypeManager.getJavaCode(foreground) + ");");
+ compiledTabInfo.appendInitializationCode(id + ".setForeground(" + compiler.getJavaCode(foreground) + ");");
} else if (name.equals("background")) {
- Color background = (Color) TypeManager.convertFromString(value, Color.class);
+ Color background = (Color) compiler.convertFromString(value, Color.class);
tabInfo.setBackground(background);
- compiledTabInfo.appendInitializationCode(id + ".setBackground(" + TypeManager.getJavaCode(background) + ");");
+ compiledTabInfo.appendInitializationCode(id + ".setBackground(" + compiler.getJavaCode(background) + ");");
} else if (name.equals("id")) {
// ignore, already handled
} else {
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -11,7 +11,6 @@
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import jaxx.compiler.tags.DefaultComponentHandler;
-import jaxx.compiler.types.TypeManager;
import jaxx.runtime.swing.Table;
import java.awt.GridBagConstraints;
@@ -77,7 +76,7 @@
rowSpans.set(x, c.gridheight);
}
- super.addChild(child, TypeManager.getJavaCode(c), compiler);
+ super.addChild(child, compiler.getJavaCode(c), compiler);
emptyCell = false;
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -421,21 +421,6 @@
}
- /*protected boolean addContextName(BeanValidatorHandler handler, JAXXCompiler compiler) {
- if (contextName != null) {
- String code = handler.getSetPropertyCode(getJavaCode(), CONTEXT_NAME_ATTRIBUTE, TypeManager.getJavaCode(contextName), compiler);
- appendAdditionCode(code);
- }
- return false;
- }*/
-
- /*protected boolean addScope(BeanValidatorHandler handler, JAXXCompiler compiler) {
- if (scope != null) {
- String code = handler.getSetPropertyCode(getJavaCode(), SCOPE_ATTRIBUTE, TypeManager.getJavaCode(scope), compiler);
- appendAdditionCode(code);
- }
- return false;
- }*/
protected boolean addParentValidator(Element tag, BeanValidatorHandler handler, JAXXCompiler compiler) {
if (parentValidator != null) {
String initializer;
@@ -556,7 +541,7 @@
String beanClassName = beanInfo.getJAXXBeanDescriptor().getClassDescriptor().getName();
// contextName must be in constructor to able to init validator with his correct contextName
- setConstructorParams(beanClassName + ".class, " + TypeManager.getJavaCode(contextName));
+ setConstructorParams(beanClassName + ".class, " + compiler.getJavaCode(contextName));
// add generic type to validator
setGenericTypes(new String[]{beanClassName});
@@ -604,12 +589,7 @@
// editor component not find on ui
continue;
}
- /*if (compiler.isComponentUsedByValidator(component)) {
- // component is already used by another validator
- compiler.reportError("component '" + component + "' is already used by another validator.");
- continue;
- }*/
- String keyCode = TypeManager.getJavaCode(propertyName);
+ String keyCode = compiler.getJavaCode(propertyName);
appendAdditionCode(getJavaCode() + ".setFieldRepresentation(" + keyCode + ", " + component + ");");
}
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tools/PrintTagInfo.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tools/PrintTagInfo.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tools/PrintTagInfo.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -2,7 +2,7 @@
import jaxx.compiler.tags.*;
import jaxx.compiler.JAXXCompiler;
-import jaxx.compiler.JAXXCompilerLaunchor;
+import jaxx.compiler.JAXXEngine;
import jaxx.compiler.beans.JAXXPropertyDescriptor;
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
@@ -36,7 +36,7 @@
}
try {
- JAXXCompilerLaunchor.loadLibraries(false);
+ JAXXEngine.loadLibraries(false);
for (int i = toFile ? 1 : 0; i < arg.length; i++) {
String className = arg[i];
treateClass(w, className);
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tools/jaxxcapture/handlers/ObjectHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tools/jaxxcapture/handlers/ObjectHandler.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tools/jaxxcapture/handlers/ObjectHandler.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,6 +1,5 @@
package jaxx.compiler.tools.jaxxcapture.handlers;
-import jaxx.compiler.JavaFile;
import jaxx.compiler.JAXXCompiler;
import jaxx.compiler.tools.jaxxcapture.CapturedObject;
import jaxx.compiler.tools.jaxxcapture.ContextNode;
@@ -17,6 +16,7 @@
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Stack;
+import jaxx.compiler.io.JavaElement;
public class ObjectHandler {
private static int count;
@@ -292,7 +292,7 @@
}
result.append(" <script>");
result.append(lineSeparator);
- result.append(JavaFile.indent(script, 4, false, lineSeparator));
+ result.append(JavaElement.indent(script, 4, false, lineSeparator));
result.append(lineSeparator);
result.append(" </script>");
result.append(lineSeparator);
@@ -314,7 +314,7 @@
String lineSeparator = JAXXCompiler.getLineSeparator();
for (CapturedObject aChildren : children) {
if (!aChildren.isInlineable()) {
- result.append(JavaFile.indent(aChildren.getXML(capture), 2, false, lineSeparator));
+ result.append(JavaElement.indent(aChildren.getXML(capture), 2, false, lineSeparator));
result.append(lineSeparator);
}
}
Added: branches/jaxx-2.X/jaxx-compiler/src/main/resources/META-INF/services/jaxx.compiler.decorators.CompiledObjectDecorator
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/resources/META-INF/services/jaxx.compiler.decorators.CompiledObjectDecorator (rev 0)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/resources/META-INF/services/jaxx.compiler.decorators.CompiledObjectDecorator 2009-10-24 11:31:57 UTC (rev 1589)
@@ -0,0 +1,3 @@
+jaxx.compiler.decorators.DefaultCompiledObjectDecorator
+jaxx.compiler.decorators.BoxedCompiledObjectDecorator
+jaxx.compiler.decorators.HelpRootCompiledObjectDecorator
Added: branches/jaxx-2.X/jaxx-compiler/src/main/resources/META-INF/services/jaxx.compiler.types.TypeConverter
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/resources/META-INF/services/jaxx.compiler.types.TypeConverter (rev 0)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/resources/META-INF/services/jaxx.compiler.types.TypeConverter 2009-10-24 11:31:57 UTC (rev 1589)
@@ -0,0 +1,5 @@
+jaxx.compiler.types.ColorConverter
+jaxx.compiler.types.GridBagConstraintsConverter
+jaxx.compiler.types.InsetsConverter
+jaxx.compiler.types.KeyStrokeConverter
+jaxx.compiler.types.PrimitiveConverter
Modified: branches/jaxx-2.X/jaxx-compiler/src/test/java/jaxx/compiler/JavaMethodTest.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/test/java/jaxx/compiler/JavaMethodTest.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/test/java/jaxx/compiler/JavaMethodTest.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,7 +1,7 @@
package jaxx.compiler;
-import jaxx.compiler.JavaMethod;
-import jaxx.compiler.JavaMethod.MethodOrder;
+import jaxx.compiler.io.JavaMethod;
+import jaxx.compiler.io.JavaMethod.MethodOrder;
import org.junit.Assert;
import org.junit.Test;
Modified: branches/jaxx-2.X/jaxx-compiler/src/test/java/jaxx/compiler/tags/TagManagerTest.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/test/java/jaxx/compiler/tags/TagManagerTest.java 2009-10-24 11:30:36 UTC (rev 1588)
+++ branches/jaxx-2.X/jaxx-compiler/src/test/java/jaxx/compiler/tags/TagManagerTest.java 2009-10-24 11:31:57 UTC (rev 1589)
@@ -1,7 +1,7 @@
package jaxx.compiler.tags;
import jaxx.compiler.JAXXCompiler;
-import jaxx.compiler.JAXXCompilerLaunchor;
+import jaxx.compiler.JAXXEngine;
import jaxx.compiler.reflect.ClassDescriptor;
import jaxx.compiler.reflect.ClassDescriptorLoader;
import org.junit.Assert;
@@ -36,8 +36,8 @@
@Before
public void setUp() {
- JAXXCompilerLaunchor.newLaunchor();
- compiler = JAXXCompilerLaunchor.createDummyCompiler(JAXXCompiler.class.getClassLoader());
+ JAXXEngine.newLaunchor();
+ compiler = JAXXEngine.createDummyCompiler(JAXXCompiler.class.getClassLoader());
// compiler = new JAXXCompiler(JAXXCompiler.class.getClassLoader());
compiler.addImport("javax.swing.*");
1
0
r1588 - branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types
by tchemit@users.nuiton.org 24 Oct '09
by tchemit@users.nuiton.org 24 Oct '09
24 Oct '09
Author: tchemit
Date: 2009-10-24 13:30:36 +0200 (Sat, 24 Oct 2009)
New Revision: 1588
Modified:
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/ColorConverter.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/GridBagConstraintsConverter.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/InsetsConverter.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/KeyStrokeConverter.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/PrimitiveConverter.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeConverter.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeManager.java
Log:
Evolution #100: am?\195?\169lioration du design du compilateur
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/ColorConverter.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/ColorConverter.java 2009-10-23 18:01:04 UTC (rev 1587)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/ColorConverter.java 2009-10-24 11:30:36 UTC (rev 1588)
@@ -10,6 +10,13 @@
public class ColorConverter implements TypeConverter {
@Override
+ public Class<?>[] getSupportedTypes() {
+ return new Class<?>[]{
+ Color.class
+ };
+ }
+
+ @Override
public String getJavaCode(Object object) {
Color color = (Color) object;
return "new Color(" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue() + ")";
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/GridBagConstraintsConverter.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/GridBagConstraintsConverter.java 2009-10-23 18:01:04 UTC (rev 1587)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/GridBagConstraintsConverter.java 2009-10-24 11:30:36 UTC (rev 1588)
@@ -9,6 +9,13 @@
public class GridBagConstraintsConverter implements TypeConverter {
@Override
+ public Class<?>[] getSupportedTypes() {
+ return new Class<?>[] {
+ GridBagConstraints.class
+ };
+ }
+
+ @Override
public String getJavaCode(Object object) {
GridBagConstraints g = (GridBagConstraints) object;
return "new GridBagConstraints(" + g.gridx + ", " + g.gridy + ", " + g.gridwidth + ", " + g.gridheight + ", " +
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/InsetsConverter.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/InsetsConverter.java 2009-10-23 18:01:04 UTC (rev 1587)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/InsetsConverter.java 2009-10-24 11:30:36 UTC (rev 1588)
@@ -10,6 +10,11 @@
public class InsetsConverter implements TypeConverter {
@Override
+ public Class<?>[] getSupportedTypes() {
+ return new Class<?>[]{Insets.class};
+ }
+
+ @Override
public String getJavaCode(Object object) {
Insets insets = (Insets) object;
return "new Insets(" + insets.top + ", " + insets.left + ", " + insets.bottom + ", " + insets.right + ")";
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/KeyStrokeConverter.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/KeyStrokeConverter.java 2009-10-23 18:01:04 UTC (rev 1587)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/KeyStrokeConverter.java 2009-10-24 11:30:36 UTC (rev 1588)
@@ -9,6 +9,11 @@
public class KeyStrokeConverter implements TypeConverter {
@Override
+ public Class<?>[] getSupportedTypes() {
+ return new Class<?>[]{KeyStroke.class};
+ }
+
+ @Override
public String getJavaCode(Object object) {
return "KeyStroke.getKeyStroke(\"" + object.toString() + "\")";
}
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/PrimitiveConverter.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/PrimitiveConverter.java 2009-10-23 18:01:04 UTC (rev 1587)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/PrimitiveConverter.java 2009-10-24 11:30:36 UTC (rev 1588)
@@ -9,6 +9,30 @@
public class PrimitiveConverter implements TypeConverter {
@Override
+ public Class<?>[] getSupportedTypes() {
+
+ return new Class<?>[]{
+ boolean.class,
+ Boolean.class,
+ byte.class,
+ Byte.class,
+ short.class,
+ Short.class,
+ int.class,
+ Integer.class,
+ long.class,
+ Long.class,
+ float.class,
+ Float.class,
+ double.class,
+ Double.class,
+ char.class,
+ Character.class,
+ String.class
+ };
+ }
+
+ @Override
public String getJavaCode(Object object) {
if (object instanceof Boolean) {
return String.valueOf(((Boolean) object).booleanValue());
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeConverter.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeConverter.java 2009-10-23 18:01:04 UTC (rev 1587)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeConverter.java 2009-10-24 11:30:36 UTC (rev 1588)
@@ -6,6 +6,8 @@
public interface TypeConverter {
+ Class<?>[] getSupportedTypes();
+
String getJavaCode(Object object);
Object convertFromString(String string, Class<?> type);
Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeManager.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeManager.java 2009-10-23 18:01:04 UTC (rev 1587)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeManager.java 2009-10-24 11:30:36 UTC (rev 1588)
@@ -6,19 +6,31 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.ServiceLoader;
public class TypeManager {
- private static Map<Class<?>, TypeConverter> converters = new HashMap<Class<?>, TypeConverter>();
+ private static Map<Class<?>, TypeConverter> converters;
+ public static Map<Class<?>, TypeConverter> getConverters() {
+ if (converters == null) {
+ converters = new HashMap<Class<?>, TypeConverter>();
+ // load converters
+ ServiceLoader<TypeConverter> loader = ServiceLoader.load(TypeConverter.class);
+ for (TypeConverter c : loader) {
+ // for each supported type, register the converter
+ for (Class<?> type : c.getSupportedTypes()) {
+ converters.put(type, c);
+ }
+ }
+ }
+ return converters;
+ }
+
private TypeManager() { /* not instantiable */ }
- public static void registerTypeConverter(Class<?> type, TypeConverter converter) {
- converters.put(type, converter);
- }
-
public static TypeConverter getTypeConverter(Class<?> type) {
- return converters.get(type);
+ return getConverters().get(type);
}
public static String getJavaCode(Object object) {
1
0
r1587 - branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by tchemit@users.nuiton.org 23 Oct '09
by tchemit@users.nuiton.org 23 Oct '09
23 Oct '09
Author: tchemit
Date: 2009-10-23 20:01:04 +0200 (Fri, 23 Oct 2009)
New Revision: 1587
Modified:
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
Log:
add gotoChildNode in NavigationTreeHelper
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2009-10-23 16:44:44 UTC (rev 1586)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2009-10-23 18:01:04 UTC (rev 1587)
@@ -143,6 +143,25 @@
}
/**
+ * Sélection d'un fils du noeud selectionne dans l'arbre de navigation.
+ *
+ * @param context le contexte applicatif
+ * @param childIndex index du fils a selectionner
+ */
+ public void gotoChildNode(JAXXContext context, int childIndex) {
+
+ NavigationTreeNode node = getSelectedNode(context);
+
+ if (node == null) {
+ // pas de noeud selectionne
+ throw new NullPointerException("no selected node in context");
+ }
+ node = node.getChildAt(childIndex);
+
+ selectNode(context, node);
+ }
+
+ /**
* Demande une opération de repaint sur un noeud de l'arbre de navigation.
*
* <b>Note:</b> La descendance du noeud n'est pas repainte.
1
0
r1586 - in branches/jaxx-2.X/jaxx-demo/src/main: java/jaxx/demo java/jaxx/demo/component/jaxx/navigation java/jaxx/demo/component/jaxx/navigation/content resources/i18n
by tchemit@users.nuiton.org 23 Oct '09
by tchemit@users.nuiton.org 23 Oct '09
23 Oct '09
Author: tchemit
Date: 2009-10-23 18:44:44 +0200 (Fri, 23 Oct 2009)
New Revision: 1586
Added:
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx
Removed:
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/BaseContent.jaxx
Modified:
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties
branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties
Log:
- add a contract NavigationContentUI and use it in NavigationTreeHandler
- improve demo
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2009-10-23 16:42:17 UTC (rev 1585)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2009-10-23 16:44:44 UTC (rev 1586)
@@ -26,6 +26,7 @@
import java.util.Locale;
import java.util.Properties;
+import jaxx.demo.component.jaxx.navigation.FullNavigationTreeDemo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -110,6 +111,11 @@
return result;
}
+ public String getDemoPath() {
+ String result = getOption(Option.DEMO_PATH.key);
+ return result;
+ }
+
public void setFullscreen(boolean fullscreen) {
Object oldValue = null;
setOption(Option.FULL_SCREEN.key, fullscreen + "");
@@ -159,7 +165,8 @@
CONFIG_FILE(CONFIG_FILE_NAME, _("jaxxdemo.config.configFileName.description"), "jaxxdemo", String.class, true, true),
FULL_SCREEN("ui.fullscreen", _("jaxxdemo.config.ui.fullscreen"), "false", Boolean.class, false, false),
- LOCALE("ui.locale", _("jaxxdemo.config.ui.locale"), Locale.FRANCE.toString(), Locale.class, false, false);
+ LOCALE("ui.locale", _("jaxxdemo.config.ui.locale"), Locale.FRANCE.toString(), Locale.class, false, false),
+ DEMO_PATH("ui.demo.path", _("jaxxdemo.config.ui.demo.path"), "$root/jaxxdemo.tree.component.jaxx/jaxxdemo.tree.component.jaxx.tree.navigation/" + FullNavigationTreeDemo.class.getSimpleName(), String.class, false, false);
public final String key;
public final String description;
public final String defaultValue;
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-10-23 16:42:17 UTC (rev 1585)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-10-23 16:44:44 UTC (rev 1586)
@@ -93,7 +93,7 @@
return ui;
}
- public void displayUI(final DemoUI ui, final NavigationTreeNode node) {
+ public void displayUI(final DemoUI ui, final String nodePath) {
// expend all nodes of the demo tree
jaxx.runtime.SwingUtil.expandTree(ui.getNavigation());
@@ -104,12 +104,12 @@
public void run() {
String path;
- if (node == null) {
+ if (nodePath == null) {
// take first node
path = "$root/jaxxdemo.tree.component.swing";
} else {
// take selected node
- path = node.getFullPath();
+ path = nodePath;
}
log.info("node to re select " + path);
// select node
@@ -146,6 +146,7 @@
DemoUI ui = getUI(rootContext);
NavigationTreeNode node = null;
+ String nodePath = null;
if (ui != null) {
@@ -154,7 +155,8 @@
node = ui.getTreeHelper().getSelectedNode(ui);
if (node != null) {
- log.info("selected node " + node.getFullPath());
+ nodePath = node.getFullPath();
+ log.info("selected node " + nodePath);
}
ErrorDialogUI.init(null);
@@ -169,7 +171,7 @@
ui = initUI(rootContext, fullscreen);
- displayUI(ui, node);
+ displayUI(ui, nodePath);
}
/**
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java 2009-10-23 16:42:17 UTC (rev 1585)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java 2009-10-23 16:44:44 UTC (rev 1586)
@@ -119,7 +119,7 @@
log.info(_("jaxxdemo.init.ui.done"));
- handler.displayUI(ui, null);
+ handler.displayUI(ui, config.getDemoPath());
} catch (Exception e) {
ErrorDialogUI.showError(e);
Deleted: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/BaseContent.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/BaseContent.jaxx 2009-10-23 16:42:17 UTC (rev 1585)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/BaseContent.jaxx 2009-10-23 16:44:44 UTC (rev 1586)
@@ -1,99 +0,0 @@
-<!--
- *##%
- jaxx-demo
- Copyright (C) 2008 - 2009 CodeLutin
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Lesser Public License for more details.
-
- You should have received a copy of the GNU General Lesser Public
- License along with this program. If not, see
- <http://www.gnu.org/licenses/lgpl-3.0.html>.
- ##%*
--->
-<JPanel layout='{new BorderLayout()}'>
-
- <Object id='data' javaBean='helper.getSelectedBean(this)'/>
-
- <script><![CDATA[
-import jaxx.runtime.SwingUtil;
-
-private final FullNavigationTreeHelper helper = new FullNavigationTreeHelper();
-
-String getType(Object data) {
- if (data == null) {
- return "no type";
- }
- if (data instanceof java.util.List<?>) {
- java.util.List<?> l = (java.util.List<?>) data;
- if (l.isEmpty()) {
- return "Empty collection";
- }
- return "Collection of " + l.size() + " " + l.get(0).getClass().getSimpleName() + "(s)";
- }
- return data.getClass().getSimpleName();
-}
-
-String getContent(Object data) {
- if (data == null) {
- return "no content";
- }
- StringBuilder buffer = new StringBuilder();
- if (data instanceof java.util.List<?>) {
- for (Object o : ((java.util.List<?>)data)) {
- buffer.append(o).append("\n");
- }
- } else {
- buffer.append(data);
- }
- return buffer.toString();
-}
-
-ImageIcon getImage(Object data) {
- if (data == null) {
- return null;
- }
- if (data instanceof Movie) {
- return SwingUtil.createIcon(((Movie)data).getImage());
- }
- if (data instanceof People) {
- return SwingUtil.createIcon(((People)data).getImage());
- }
- return null;
-}
- ]]>
- </script>
-
- <JSplitPane id='splitPane'
- orientation='{JSplitPane.VERTICAL_SPLIT}'
- resizeWeight='0.5'
- constraints='BorderLayout.CENTER'
- oneTouchExpandable='true'>
-
- <JScrollPane border='{null}'
- horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
- verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
- <JTextPane border='{new TitledBorder("Content Type : " + getType(getData()))}'
- editable='false'
- font-size='11'
- text='{getContent(getData())}'/>
- </JScrollPane>
-
- <JScrollPane border='{new TitledBorder("Picture")}'
- horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED}'
- verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'
- minimumSize='{SwingUtil.newMinDimension()}'>
-
- <JLabel horizontalAlignment='center' icon='{getImage(getData())}'/>
-
- </JScrollPane>
-
- </JSplitPane>
-</JPanel>
\ No newline at end of file
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx 2009-10-23 16:42:17 UTC (rev 1585)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx 2009-10-23 16:44:44 UTC (rev 1586)
@@ -28,12 +28,12 @@
import jaxx.runtime.SwingUtil;
private final FullNavigationTreeHelper helper = new FullNavigationTreeHelper();
-
+setContextValue(helper);
helper.createModel(this);
@Override
protected String[] getSources() {
- return new String[]{ getDefaultSource(), "BaseContent.jaxx", "FullNavigationTreeHelper.java", "Movie.java", "People.java" };
+ return new String[]{ getDefaultSource(), "FullNavigationTreeHelper.java", "Movie.java", "People.java" };
}
private void $afterCompleteSetup() {
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2009-10-23 16:42:17 UTC (rev 1585)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2009-10-23 16:44:44 UTC (rev 1586)
@@ -23,7 +23,6 @@
import jaxx.runtime.JAXXObject;
import jaxx.runtime.JAXXContext;
import jaxx.runtime.context.JAXXContextEntryDef;
-import jaxx.runtime.decorator.Decorator;
import jaxx.runtime.decorator.DecoratorUtils;
import jaxx.runtime.swing.CardLayout2;
import jaxx.runtime.swing.ErrorDialogUI;
@@ -31,13 +30,10 @@
import jaxx.runtime.swing.navigation.NavigationTreeHandler.Strategy;
import jaxx.runtime.swing.navigation.NavigationTreeHandlerWithCardLayout;
import jaxx.runtime.swing.navigation.NavigationTreeHelper;
-import jaxx.runtime.swing.navigation.NavigationTreeModelBuilder;
-import jaxx.runtime.swing.navigation.NavigationTreeNode;
import jaxx.runtime.swing.navigation.NavigationTreeModel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import static org.nuiton.i18n.I18n._;
import java.util.Arrays;
import java.util.List;
@@ -74,6 +70,7 @@
* where the actors are hold in context
*/
static public final JAXXContextEntryDef<List<People>> ACTORS = Util.newListContextEntryDef("actors");
+ protected FullNavigationTreeModelBuilder builder;
public FullNavigationTreeHelper() {
super("full");
@@ -85,6 +82,7 @@
* @param context the context where to hold the model
*/
public void createModel(JAXXContext context) {
+ log.info("for " + this);
People a = new People("0", "Jack", "Black", 0, "/jaxx/demo/images/jack.jpg");
People a2 = new People("1", "Héctor", "Jiménez", 0, "/jaxx/demo/images/hector.jpg");
People a3 = new People("2", "Ana", "de la Reguera", 0, "/jaxx/demo/images/ana.jpg");
@@ -105,87 +103,14 @@
@Override
public NavigationTreeModel createTreeModel(JAXXContext context) {
- List<Movie> movies = MOVIES.getContextValue(context);
- List<People> actors = ACTORS.getContextValue(context);
-
- if (log.isDebugEnabled()) {
- log.debug("for " + movies.size() + " movie(s)");
+ if (builder == null) {
+ builder = new FullNavigationTreeModelBuilder(context);
}
- NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder("/", context, BaseContent.class,
- null);
+ builder.createInitialModel();
- Decorator<Movie> mDecorator = DecoratorUtils.get(Movie.class.getSimpleName());
- Decorator<People> pDecorator = DecoratorUtils.get(People.class.getSimpleName());
-
- // construction du noeud root
- // il ne contient pas de context et ne sera pas visible
- NavigationTreeNode rootNode = builder.buildEmptyRoot(null, "$root");
-
- // construction du noeud avec les films recupere la liste des films
- // dans le context avec la clef movies
- // navigation path = $root/movies
- NavigationTreeNode moviesNode = builder.build(
- rootNode,
- _("movies"),
- MOVIES,
- "movies",
- null,
- null);
-
- for (Movie m : movies) {
-
- // navigation path = $root/movies/m.id
- NavigationTreeNode movieNode = builder.build(
- moviesNode,
- mDecorator,
- "..[@id=\"" + m.getId() + "\"]",
- m.getId(),
- null,
- null);
-
- // navigation path = $root/movies/m.id/actors
- NavigationTreeNode actorsNode = builder.build(
- movieNode,
- _("actors"),
- "../actors",
- "actors",
- null,
- null);
-
- for (People p : m.getActors()) {
- // navigation path = $root/movies/m.id/actors/p.id
- builder.build(
- actorsNode,
- pDecorator,
- "..[@id=\"" + p.getId() + "\"]",
- p.getId(),
- null,
- null);
- }
- }
-
- // construction du noeud avec les acteurs
- NavigationTreeNode actorsNode = builder.build(rootNode, _("actors"),
- ACTORS,
- "actors", null, null);
-
- for (People p : actors) {
- // navigation path = $root/actors/p.id
- builder.build(
- actorsNode,
- pDecorator,
- "..[@id=\"" + p.getId() + "\"]",
- p.getId(),
- null,
- null);
- }
NavigationTreeModel model = builder.getModel();
- if (log.isDebugEnabled()) {
- builder.printModel(model.getRoot());
- }
-
// save tree model in context
setTreeModel(context, model);
return model;
@@ -203,7 +128,7 @@
handler = new NavigationTreeHandlerWithCardLayout(
getPrefix(),
context,
- Strategy.PER_NODE) {
+ Strategy.PER_UI_TYPE) {
private static final long serialVersionUID = 1L;
Added: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java (rev 0)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2009-10-23 16:44:44 UTC (rev 1586)
@@ -0,0 +1,120 @@
+package jaxx.demo.component.jaxx.navigation;
+
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.decorator.Decorator;
+import jaxx.runtime.decorator.DecoratorUtils;
+import jaxx.runtime.swing.navigation.NavigationTreeModelBuilder;
+import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import jaxx.demo.component.jaxx.navigation.content.*;
+import static org.nuiton.i18n.I18n._;
+
+import java.util.List;
+
+/**
+ *
+ * @author chemit
+ * @since 2.0.0
+ */
+public class FullNavigationTreeModelBuilder extends NavigationTreeModelBuilder {
+
+ private static final long serialVersionUID = 1l;
+ /**
+ * Logger
+ */
+ static private final Log log = LogFactory.getLog(FullNavigationTreeModelBuilder.class);
+
+ protected FullNavigationTreeModelBuilder(JAXXContext context) {
+ super("/", context, null, null);
+ }
+
+ public void addMovie(Movie movie) {
+ //TODO
+ }
+
+ public void addActor(People people,Movie... movies) {
+ //TODO
+ }
+
+ public void createInitialModel() {
+
+ List<Movie> movies = FullNavigationTreeHelper.MOVIES.getContextValue(getModel().getContext());
+ List<People> actors = FullNavigationTreeHelper.ACTORS.getContextValue(getModel().getContext());
+
+ if (log.isDebugEnabled()) {
+ log.debug("for " + movies.size() + " movie(s)");
+ }
+
+
+ Decorator<Movie> mDecorator = DecoratorUtils.get(Movie.class.getSimpleName());
+ Decorator<People> pDecorator = DecoratorUtils.get(People.class.getSimpleName());
+
+ // construction du noeud root
+ // il ne contient pas de context et ne sera pas visible
+ NavigationTreeNode rootNode = this.buildEmptyRoot(null, "$root");
+
+ // construction du noeud avec les films recupere la liste des films
+ // dans le context avec la clef movies
+ // navigation path = $root/movies
+ NavigationTreeNode moviesNode = this.build(
+ rootNode,
+ _("movies"),
+ FullNavigationTreeHelper.MOVIES,
+ "movies",
+ MoviesContentUI.class,
+ null);
+
+ for (Movie m : movies) {
+
+ // navigation path = $root/movies/m.id
+ NavigationTreeNode movieNode = this.build(
+ moviesNode,
+ mDecorator,
+ "..[@id=\"" + m.getId() + "\"]",
+ m.getId(),
+ MovieContentUI.class,
+ null);
+
+ // navigation path = $root/movies/m.id/actors
+ NavigationTreeNode actorsNode = this.build(
+ movieNode,
+ _("actors"),
+ "../actors",
+ "actors",
+ ActorsContentUI.class,
+ null);
+
+ for (People p : m.getActors()) {
+ // navigation path = $root/movies/m.id/actors/p.id
+ this.build(
+ actorsNode,
+ pDecorator,
+ "..[@id=\"" + p.getId() + "\"]",
+ p.getId(),
+ ActorContentUI.class,
+ null);
+ }
+ }
+
+ // construction du noeud avec les acteurs
+ NavigationTreeNode actorsNode = this.build(rootNode, _("actors"),
+ FullNavigationTreeHelper.ACTORS,
+ "actors", ActorsContentUI.class, null);
+
+ for (People p : actors) {
+ // navigation path = $root/actors/p.id
+ this.build(
+ actorsNode,
+ pDecorator,
+ "..[@id=\"" + p.getId() + "\"]",
+ p.getId(),
+ ActorContentUI.class,
+ null);
+ }
+
+ if (log.isDebugEnabled()) {
+ printModel(getModel().getRoot());
+ }
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx (rev 0)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx 2009-10-23 16:44:44 UTC (rev 1586)
@@ -0,0 +1,111 @@
+<!--
+ *##%
+ jaxx-demo
+ Copyright (C) 2008 - 2009 CodeLutin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ ##%*
+-->
+<JPanel layout='{new BorderLayout()}' implements='jaxx.runtime.swing.navigation.NavigationContentUI'>
+
+ <script><![CDATA[
+import jaxx.runtime.SwingUtil;
+import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.demo.component.jaxx.navigation.*;
+
+@Override
+public void openUI(NavigationTreeNode node) throws Exception {
+ People p = (People) getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this);
+ log.info("selected people = "+p);
+ setData(p);
+}
+
+@Override
+public void closeUI(NavigationTreeNode node) throws Exception {
+// nothing to do
+}
+
+String getType(Object data) {
+ if (data == null) {
+ return "no type";
+ }
+ if (data instanceof java.util.List<?>) {
+ java.util.List<?> l = (java.util.List<?>) data;
+ if (l.isEmpty()) {
+ return "Empty collection";
+ }
+ return "Collection of " + l.size() + " " + l.get(0).getClass().getSimpleName() + "(s)";
+ }
+ return data.getClass().getSimpleName();
+}
+
+String getContent(Object data) {
+ if (data == null) {
+ return "no content";
+ }
+ StringBuilder buffer = new StringBuilder();
+ if (data instanceof java.util.List<?>) {
+ for (Object o : ((java.util.List<?>)data)) {
+ buffer.append(o).append("\n");
+ }
+ } else {
+ buffer.append(data);
+ }
+ return buffer.toString();
+}
+
+ImageIcon getImage(Object data) {
+ if (data == null) {
+ return null;
+ }
+ if (data instanceof Movie) {
+ return SwingUtil.createIcon(((Movie)data).getImage());
+ }
+ if (data instanceof People) {
+ return SwingUtil.createIcon(((People)data).getImage());
+ }
+ return null;
+}
+ ]]>
+ </script>
+
+ <People id='data' javaBean='(People) getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this)'/>
+
+ <JSplitPane id='splitPane'
+ orientation='{JSplitPane.VERTICAL_SPLIT}'
+ resizeWeight='0.5'
+ constraints='BorderLayout.CENTER'
+ oneTouchExpandable='true'>
+
+ <JScrollPane border='{null}'
+ horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
+ verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
+ <JTextPane border='{new TitledBorder("Content Type : " + getType(getData()))}'
+ editable='false'
+ font-size='11'
+ text='{getContent(getData())}'/>
+ </JScrollPane>
+
+ <JScrollPane border='{new TitledBorder("Picture")}'
+ horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED}'
+ verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'
+ minimumSize='{SwingUtil.newMinDimension()}'>
+
+ <JLabel horizontalAlignment='center' icon='{getImage(getData())}'/>
+
+ </JScrollPane>
+
+ </JSplitPane>
+</JPanel>
\ No newline at end of file
Added: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx (rev 0)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2009-10-23 16:44:44 UTC (rev 1586)
@@ -0,0 +1,88 @@
+<!--
+ *##%
+ jaxx-demo
+ Copyright (C) 2008 - 2009 CodeLutin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ ##%*
+-->
+<JPanel layout='{new BorderLayout()}' implements='jaxx.runtime.swing.navigation.NavigationContentUI'>
+
+ <script><![CDATA[
+import jaxx.runtime.SwingUtil;
+import jaxx.demo.component.jaxx.navigation.*;
+import jaxx.runtime.decorator.DecoratorUtils;
+import jaxx.runtime.decorator.swing.DecoratorListCellRenderer;
+import jaxx.runtime.swing.navigation.NavigationTreeNode;
+
+@Override
+public void openUI(NavigationTreeNode node) throws Exception {
+ java.util.List<People> ps = (java.util.List<People>)getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this);
+ log.info("selected peoples = "+ps.size());
+ setData(ps);
+}
+
+@Override
+public void closeUI(NavigationTreeNode node) throws Exception {
+// nothing to do
+}
+
+String getType(Object data) {
+ if (data == null) {
+ return "no type";
+ }
+ if (data instanceof java.util.List<?>) {
+ java.util.List<?> l = (java.util.List<?>) data;
+ if (l.isEmpty()) {
+ return "Empty collection";
+ }
+ return "Collection of " + l.size() + " " + l.get(0).getClass().getSimpleName() + "(s)";
+ }
+ return data.getClass().getSimpleName();
+}
+
+ListModel getModel(java.util.List<People> data) {
+
+ DefaultListModel model = new DefaultListModel();
+ for (People m : data) {
+ model.addElement(m);
+ }
+ return model;
+}
+
+ ]]>
+ </script>
+
+ <java.util.List id='data'
+ genericType='People'
+ javaBean='(java.util.List<People>)getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this)'/>
+
+ <JScrollPane border='{new TitledBorder("Content Type : " + getType(getData()))}'
+ constraints='BorderLayout.CENTER'
+ columnHeaderView='{toolbar}'
+ horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
+ verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
+ <JList id='list' model='{getModel(getData())}' cellRenderer='{new DecoratorListCellRenderer(DecoratorUtils.get(People.class.getSimpleName()))}'/>
+ </JScrollPane>
+ <JToolBar id='toolbar' constraints='BorderLayout.SOUTH'
+ floatable='false'>
+ <JPanel layout='{new GridLayout(1,0)}'>
+ <JButton text='jaxxdemo.action.show' enabled='{list.getSelectedIndex()!=-1}'/>
+ <JButton text='jaxxdemo.action.add'/>
+ <JButton text='jaxxdemo.action.remove' enabled='{list.getSelectedIndex()!=-1}'/>
+ </JPanel>
+ </JToolBar>
+
+</JPanel>
\ No newline at end of file
Added: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx (rev 0)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx 2009-10-23 16:44:44 UTC (rev 1586)
@@ -0,0 +1,111 @@
+<!--
+ *##%
+ jaxx-demo
+ Copyright (C) 2008 - 2009 CodeLutin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ ##%*
+-->
+<JPanel layout='{new BorderLayout()}' implements='jaxx.runtime.swing.navigation.NavigationContentUI'>
+
+ <script><![CDATA[
+import jaxx.runtime.SwingUtil;
+import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.demo.component.jaxx.navigation.*;
+
+@Override
+public void openUI(NavigationTreeNode node) throws Exception {
+ Movie m = (Movie) getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this);
+ log.info("selected movie = "+m);
+ setData(m);
+}
+
+@Override
+public void closeUI(NavigationTreeNode node) throws Exception {
+// nothing to do
+}
+
+String getType(Object data) {
+ if (data == null) {
+ return "no type";
+ }
+ if (data instanceof java.util.List<?>) {
+ java.util.List<?> l = (java.util.List<?>) data;
+ if (l.isEmpty()) {
+ return "Empty collection";
+ }
+ return "Collection of " + l.size() + " " + l.get(0).getClass().getSimpleName() + "(s)";
+ }
+ return data.getClass().getSimpleName();
+}
+
+String getContent(Object data) {
+ if (data == null) {
+ return "no content";
+ }
+ StringBuilder buffer = new StringBuilder();
+ if (data instanceof java.util.List<?>) {
+ for (Object o : ((java.util.List<?>)data)) {
+ buffer.append(o).append("\n");
+ }
+ } else {
+ buffer.append(data);
+ }
+ return buffer.toString();
+}
+
+ImageIcon getImage(Object data) {
+ if (data == null) {
+ return null;
+ }
+ if (data instanceof Movie) {
+ return SwingUtil.createIcon(((Movie)data).getImage());
+ }
+ if (data instanceof People) {
+ return SwingUtil.createIcon(((People)data).getImage());
+ }
+ return null;
+}
+ ]]>
+ </script>
+
+ <Movie id='data' javaBean='(Movie) getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this)'/>
+
+ <JSplitPane id='splitPane'
+ orientation='{JSplitPane.VERTICAL_SPLIT}'
+ resizeWeight='0.5'
+ constraints='BorderLayout.CENTER'
+ oneTouchExpandable='true'>
+
+ <JScrollPane border='{null}'
+ horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
+ verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
+ <JTextPane border='{new TitledBorder("Content Type : " + getType(getData()))}'
+ editable='false'
+ font-size='11'
+ text='{getContent(getData())}'/>
+ </JScrollPane>
+
+ <JScrollPane border='{new TitledBorder("Picture")}'
+ horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED}'
+ verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'
+ minimumSize='{SwingUtil.newMinDimension()}'>
+
+ <JLabel horizontalAlignment='center' icon='{getImage(getData())}'/>
+
+ </JScrollPane>
+
+ </JSplitPane>
+</JPanel>
\ No newline at end of file
Added: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx (rev 0)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2009-10-23 16:44:44 UTC (rev 1586)
@@ -0,0 +1,86 @@
+<!--
+ *##%
+ jaxx-demo
+ Copyright (C) 2008 - 2009 CodeLutin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ ##%*
+-->
+<JPanel layout='{new BorderLayout()}' implements='jaxx.runtime.swing.navigation.NavigationContentUI'>
+
+ <script><![CDATA[
+import jaxx.runtime.SwingUtil;
+import jaxx.demo.component.jaxx.navigation.*;
+import jaxx.runtime.decorator.DecoratorUtils;
+import jaxx.runtime.decorator.swing.DecoratorListCellRenderer;
+import jaxx.runtime.swing.navigation.NavigationTreeNode;
+
+@Override
+public void openUI(NavigationTreeNode node) throws Exception {
+ java.util.List<Movie> ms = (java.util.List<Movie>)getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this);
+ log.info("selected movies = "+ms.size());
+ setData(ms);
+}
+
+@Override
+public void closeUI(NavigationTreeNode node) throws Exception {
+// nothing to do
+}
+String getType(Object data) {
+ if (data == null) {
+ return "no type";
+ }
+ if (data instanceof java.util.List<?>) {
+ java.util.List<?> l = (java.util.List<?>) data;
+ if (l.isEmpty()) {
+ return "Empty collection";
+ }
+ return "Collection of " + l.size() + " " + l.get(0).getClass().getSimpleName() + "(s)";
+ }
+ return data.getClass().getSimpleName();
+}
+
+ListModel getModel(java.util.List<Movie> data) {
+ DefaultListModel model = new DefaultListModel();
+ for (Movie m : data) {
+ model.addElement(m);
+ }
+ return model;
+}
+
+ ]]>
+ </script>
+
+ <java.util.List id='data'
+ genericType='Movie'
+ javaBean='(java.util.List<Movie>)getContextValue(FullNavigationTreeHelper.class).getSelectedBean(this)'/>
+
+ <JScrollPane border='{new TitledBorder("Content Type : " + getType(getData()))}'
+ constraints='BorderLayout.CENTER'
+ columnHeaderView='{toolbar}'
+ horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
+ verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
+ <JList id='list' model='{getModel(getData())}' cellRenderer='{new DecoratorListCellRenderer(DecoratorUtils.get(Movie.class.getSimpleName()))}'/>
+ </JScrollPane>
+ <JToolBar id='toolbar' opaque='false' constraints='BorderLayout.SOUTH'
+ floatable='false'>
+ <JPanel layout='{new GridLayout(1,0)}'>
+ <JButton text='jaxxdemo.action.show' enabled='{list.getSelectedIndex()!=-1}'/>
+ <JButton text='jaxxdemo.action.add'/>
+ <JButton text='jaxxdemo.action.remove' enabled='{list.getSelectedIndex()!=-1}'/>
+ </JPanel>
+ </JToolBar>
+
+</JPanel>
\ No newline at end of file
Modified: branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties 2009-10-23 16:42:17 UTC (rev 1585)
+++ branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties 2009-10-23 16:44:44 UTC (rev 1586)
@@ -117,6 +117,7 @@
jaxxdemo.about.message=<h3>JAXX Demo</h3><hr/>For more informations, viste the <a href\="http\://maven-site.nuiton.org/jaxx/jaxx-demo">website of the project</a>.
jaxxdemo.action.about=About...
jaxxdemo.action.about.tip=About JAXXDemo...
+jaxxdemo.action.add=
jaxxdemo.action.configuration=Preferences
jaxxdemo.action.configuration.tip=Change the preferences of the application
jaxxdemo.action.exit=Quit
@@ -131,6 +132,8 @@
jaxxdemo.action.locale.uk.tip=Change to english language
jaxxdemo.action.normalscreen=Normal screen
jaxxdemo.action.normalscreen.tip=Change to normal screen mode
+jaxxdemo.action.remove=
+jaxxdemo.action.show=
jaxxdemo.action.site=Web site
jaxxdemo.action.site.tip=Go to the web site
jaxxdemo.config.category.directories=Files
@@ -138,6 +141,7 @@
jaxxdemo.config.category.other=Others
jaxxdemo.config.category.other.description=Others preferences
jaxxdemo.config.configFileName.description=Configuration file name
+jaxxdemo.config.ui.demo.path=
jaxxdemo.config.ui.fullscreen=To change the screen mode (true for full screen)
jaxxdemo.config.ui.locale=Locale of the application
jaxxdemo.i18neditor.configuration=Configuration
@@ -189,5 +193,6 @@
numbereditor.type=Type
numbereditor.with.auto.popup=With auto popup
numbereditor.without.auto.popup=Without auto popup
+test=
valid=
x=
Modified: branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties 2009-10-23 16:42:17 UTC (rev 1585)
+++ branches/jaxx-2.X/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties 2009-10-23 16:44:44 UTC (rev 1586)
@@ -117,6 +117,7 @@
jaxxdemo.about.message=<h3>JAXX Demo</h3><hr/>Pour plus d'informations, vous pouvez visiter le <a href\="http\://maven-site.nuiton.org/jaxx/jaxx-demo">site du projet</a>.
jaxxdemo.action.about=A propos
jaxxdemo.action.about.tip=A propos de JAXX Demo...
+jaxxdemo.action.add=
jaxxdemo.action.configuration=Configuration
jaxxdemo.action.configuration.tip=Modifier la configuration
jaxxdemo.action.exit=Quitter
@@ -131,6 +132,8 @@
jaxxdemo.action.locale.uk.tip=Changer la langue en anglais
jaxxdemo.action.normalscreen=Ecran normal
jaxxdemo.action.normalscreen.tip=Revenir en mode normal
+jaxxdemo.action.remove=
+jaxxdemo.action.show=
jaxxdemo.action.site=Site internet
jaxxdemo.action.site.tip=Acc\u00E9der au site de l'application sur internet
jaxxdemo.config.category.directories=R\u00E9pertoires
@@ -138,6 +141,7 @@
jaxxdemo.config.category.other=Autre
jaxxdemo.config.category.other.description=Autres options
jaxxdemo.config.configFileName.description=Le nom du fichier de configuration
+jaxxdemo.config.ui.demo.path=
jaxxdemo.config.ui.fullscreen=Pour afficher l'aplication en mode pleine \u00E9cran
jaxxdemo.config.ui.locale=Langue utilis\u00E9e par l'application (fr_FR, en_GB ou es_ES)
jaxxdemo.i18neditor.configuration=Configuration
@@ -189,5 +193,6 @@
numbereditor.type=Type d'\u00E9diteur
numbereditor.with.auto.popup=Avec popup auto
numbereditor.without.auto.popup=Sans popup auto
+test=
valid=valide
x=x
1
0
r1585 - branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by tchemit@users.nuiton.org 23 Oct '09
by tchemit@users.nuiton.org 23 Oct '09
23 Oct '09
Author: tchemit
Date: 2009-10-23 18:42:17 +0200 (Fri, 23 Oct 2009)
New Revision: 1585
Added:
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java
Modified:
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java
Log:
- add a contract NavigationContentUI and use it in NavigationTreeHandler
Added: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java (rev 0)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java 2009-10-23 16:42:17 UTC (rev 1585)
@@ -0,0 +1,29 @@
+package jaxx.runtime.swing.navigation;
+
+/**
+ * Basic contract on a content UI.
+ *
+ * @author chemit
+ * @since 2.0.0
+ */
+public interface NavigationContentUI {
+
+ /**
+ * Init the ui just before been opened by the method
+ * {@link NavigationTreeHandler#openUI(java.awt.Component, jaxx.runtime.swing.navigation.NavigationTreeNode)}.
+ *
+ * @param node the selected node associated to the ui
+ * @throws Exception
+ * @see NavigationTreeHandler#openUI(java.awt.Component, jaxx.runtime.swing.navigation.NavigationTreeNode)
+ */
+ void openUI(NavigationTreeNode node) throws Exception;
+
+ /**
+ * Clean the ui after been closed by the method {@link NavigationTreeHandler#closeUI(java.awt.Component)}.
+ *
+ * @param node the selected node associated to the ui
+ * @throws Exception
+ * @see NavigationTreeHandler#closeUI(java.awt.Component)
+ */
+ void closeUI(NavigationTreeNode node) throws Exception;
+}
Property changes on: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2009-10-23 14:30:44 UTC (rev 1584)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2009-10-23 16:42:17 UTC (rev 1585)
@@ -170,6 +170,9 @@
// can not changed current node
return;
}
+ if (component instanceof NavigationContentUI) {
+ ((NavigationContentUI) component).closeUI((NavigationTreeNode) path.getLastPathComponent());
+ }
} catch (Exception ex) {
treateError(ex);
return;
@@ -217,6 +220,9 @@
helper.setSelectedNode(ctxt, node);
// really open the ui associated with the selected node
+ if (newUI instanceof NavigationContentUI) {
+ ((NavigationContentUI) newUI).openUI(node);
+ }
openUI(newUI, node);
} catch (Exception e) {
1
0
r1584 - branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by sletellier@users.nuiton.org 23 Oct '09
by sletellier@users.nuiton.org 23 Oct '09
23 Oct '09
Author: sletellier
Date: 2009-10-23 16:30:44 +0200 (Fri, 23 Oct 2009)
New Revision: 1584
Modified:
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
Log:
Adding repaint node mathods
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2009-10-22 10:57:40 UTC (rev 1583)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2009-10-23 14:30:44 UTC (rev 1584)
@@ -1,6 +1,7 @@
package jaxx.runtime.swing.navigation;
import java.lang.reflect.InvocationTargetException;
+import java.util.Enumeration;
import java.util.regex.Pattern;
import javax.swing.JTree;
import javax.swing.tree.TreePath;
@@ -123,6 +124,63 @@
tree.scrollPathToVisible(path);
}
+ /**
+ * Sélection du parent du noeud selectionne dans l'arbre de navigation.
+ *
+ * @param context le contexte applicatif
+ */
+ public void gotoParentNode(JAXXContext context) {
+
+ NavigationTreeNode node = getSelectedNode(context);
+
+ if (node == null) {
+ // pas de noeud selectionne
+ throw new NullPointerException("no selected node in context");
+ }
+ node = node.getParent();
+
+ selectNode(context, node);
+ }
+
+ /**
+ * Demande une opération de repaint sur un noeud de l'arbre de navigation.
+ *
+ * <b>Note:</b> La descendance du noeud n'est pas repainte.
+ *
+ * @param context le contexte applicatif
+ * @param node le noeud à repaindre
+ */
+ public void repaintNode(JAXXContext context, NavigationTreeNode node) {
+ repaintNode(context, node, false);
+ }
+
+ /**
+ * Demande une opération de repaint sur un noeud de l'arbre de navigation.
+ *
+ * <b>Note:</b> La descendance du noeud est repainte si le paramètre
+ * <code>deep</code> est à <code>true</code>.
+ *
+ * @param context le contexte applicatif
+ * @param node le noeud à repaindre
+ * @param deep un flag pour activer la repainte de la descendance du noeud
+ */
+ public void repaintNode(JAXXContext context, NavigationTreeNode node, boolean deep) {
+ NavigationTreeModel navigationModel = getSafeTreeModel(context);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ navigationModel.nodeChanged(node);
+ if (deep) {
+ // repaint childs nodes
+ //todo we should only repaint necessary nodes ?
+ Enumeration<?> e = node.children();
+ while (e.hasMoreElements()) {
+ NavigationTreeNode child = (NavigationTreeNode) e.nextElement();
+ repaintNode(context, child, true);
+ }
+ }
+ }
+
public NavigationTreeModel getSafeTreeModel(JAXXContext context) throws NullPointerException {
NavigationTreeModel treeModel = getTreeModel(context);
if (treeModel == null) {
1
0
r1583 - in branches/jaxx-2.X: jaxx-demo/src/main/java/jaxx/demo jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation jaxx-runtime/src/main/java/jaxx/runtime jaxx-runtime/src/main/java/jaxx/runtime/context jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation
by tchemit@users.nuiton.org 22 Oct '09
by tchemit@users.nuiton.org 22 Oct '09
22 Oct '09
Author: tchemit
Date: 2009-10-22 12:57:40 +0200 (Thu, 22 Oct 2009)
New Revision: 1583
Modified:
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/Util.java
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/JAXXContextEntryDef.java
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
branches/jaxx-2.X/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
Log:
move context entry def static methods to jaxx.runtime.Util
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2009-10-21 13:16:51 UTC (rev 1582)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2009-10-22 10:57:40 UTC (rev 1583)
@@ -189,7 +189,7 @@
/**
* la definition de l'unqiue object a partage
*/
- static private final JAXXContextEntryDef<DemoConfig> def = JAXXContextEntryDef.newDef(DemoConfig.class);
+ static private final JAXXContextEntryDef<DemoConfig> def = jaxx.runtime.Util.newContextEntryDef(DemoConfig.class);
/**
* la pile des noeuds parent
*/
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-10-21 13:16:51 UTC (rev 1582)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-10-22 10:57:40 UTC (rev 1583)
@@ -51,7 +51,7 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(DemoUIHandler.class);
- static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = JAXXContextEntryDef.newDef("mainui", DemoUI.class);
+ static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = jaxx.runtime.Util.newContextEntryDef("mainui", DemoUI.class);
/**
* Methode pour initialiser l'ui principale sans l'afficher.
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2009-10-21 13:16:51 UTC (rev 1582)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2009-10-22 10:57:40 UTC (rev 1583)
@@ -23,7 +23,6 @@
import jaxx.runtime.JAXXObject;
import jaxx.runtime.JAXXContext;
import jaxx.runtime.context.JAXXContextEntryDef;
-import static jaxx.runtime.context.JAXXContextEntryDef.newListDef;
import jaxx.runtime.decorator.Decorator;
import jaxx.runtime.decorator.DecoratorUtils;
import jaxx.runtime.swing.CardLayout2;
@@ -43,6 +42,7 @@
import java.util.Arrays;
import java.util.List;
import javax.swing.JPanel;
+import jaxx.runtime.Util;
/**
*
@@ -69,11 +69,11 @@
/**
* where the movies are hold in context
*/
- static public final JAXXContextEntryDef<List<Movie>> MOVIES = JAXXContextEntryDef.newListDef("movies");
+ static public final JAXXContextEntryDef<List<Movie>> MOVIES = Util.newListContextEntryDef("movies");
/**
* where the actors are hold in context
*/
- static public final JAXXContextEntryDef<List<People>> ACTORS = JAXXContextEntryDef.newListDef("actors");
+ static public final JAXXContextEntryDef<List<People>> ACTORS = Util.newListContextEntryDef("actors");
public FullNavigationTreeHelper() {
super("full");
@@ -128,7 +128,7 @@
NavigationTreeNode moviesNode = builder.build(
rootNode,
_("movies"),
- newListDef("movies"),
+ MOVIES,
"movies",
null,
null);
@@ -167,7 +167,7 @@
// construction du noeud avec les acteurs
NavigationTreeNode actorsNode = builder.build(rootNode, _("actors"),
- newListDef("actors"),
+ ACTORS,
"actors", null, null);
for (People p : actors) {
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/Util.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/Util.java 2009-10-21 13:16:51 UTC (rev 1582)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/Util.java 2009-10-22 10:57:40 UTC (rev 1583)
@@ -20,6 +20,7 @@
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.EventListener;
import java.util.List;
import java.util.Map;
@@ -84,6 +85,32 @@
}
}
+ public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) {
+ return newContextEntryDef(null, klass);
+ }
+
+ public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) {
+ return new JAXXContextEntryDef<O>(name, klass);
+ }
+
+ public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() {
+ return newListContextEntryDef(null);
+ }
+
+ //@SuppressWarnings({"unchecked"})
+ public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) {
+ Class<List<O>> castList = Util.<O>castList();
+ JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name,castList);
+ return contextEntryDef;
+ }
+
+
+ @SuppressWarnings({"unchecked"})
+ protected static <O> Class<List<O>> castList() {
+ return (Class<List<O>>) Collections.emptyList().getClass();
+ }
+
+
/**
* Method to initialize the context of a ui.
*
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2009-10-21 13:16:51 UTC (rev 1582)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2009-10-22 10:57:40 UTC (rev 1583)
@@ -1,7 +1,7 @@
package jaxx.runtime.context;
import jaxx.runtime.*;
-import static jaxx.runtime.context.JAXXContextEntryDef.newDef;
+import jaxx.runtime.Util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -27,7 +27,7 @@
/**
* entry of the parent context
*/
- protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = newDef(JAXXContext.class);
+ protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = Util.newContextEntryDef(JAXXContext.class);
/**
* Logger
*/
@@ -174,7 +174,7 @@
}
protected JAXXContextEntryDef<?> getKey(String name, Class<?> klass) {
- return JAXXContextEntryDef.newDef(name, klass);
+ return Util.newContextEntryDef(name, klass);
}
@SuppressWarnings({"unchecked"})
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/JAXXContextEntryDef.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/JAXXContextEntryDef.java 2009-10-21 13:16:51 UTC (rev 1582)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/JAXXContextEntryDef.java 2009-10-22 10:57:40 UTC (rev 1583)
@@ -1,13 +1,12 @@
package jaxx.runtime.context;
+import java.util.List;
import jaxx.runtime.JAXXContext;
-import java.util.Collections;
-import java.util.List;
/**
* To qualify an entry in a {@link JAXXContext}.
* <p/>
- * Use the factory methods <code>newDef</code> and <code>newListDef</code< to obtain new instances.
+ * Use the factory methods <code>newContextEntryDef</code> and <code>newListContextEntryDef</code< to obtain new instances.
*
* @param <O> type of the entry associated to the definition
* @author chemit
@@ -22,26 +21,27 @@
private static final long serialVersionUID = 1L;
- public static <O> JAXXContextEntryDef<O> newDef(Class<O> klass) {
- return newDef(null, klass);
- }
+// public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) {
+// return newContextEntryDef(null, klass);
+// }
+//
+// public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) {
+// return new JAXXContextEntryDef<O>(name, klass);
+// }
+//
+// public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() {
+// return newListContextEntryDef(null);
+// }
+//
+// @SuppressWarnings({"unchecked"})
+// public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) {
+// Class<List<O>> castList = JAXXContextEntryDef.<O>castList();
+// JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name,castList);
+// contextEntryDef.klass = castList;
+// return contextEntryDef;
+// }
- public static <O> JAXXContextEntryDef<O> newDef(String name, Class<O> klass) {
- return new JAXXContextEntryDef<O>(name, klass);
- }
- public static <O> JAXXContextEntryDef<List<O>> newListDef() {
- return newListDef(null);
- }
-
- @SuppressWarnings({"unchecked"})
- public static <O> JAXXContextEntryDef<List<O>> newListDef(String name) {
- JAXXContextEntryDef contextEntryDef = new JAXXContextEntryDef<List<O>>(name, JAXXContextEntryDef.<O>castList());
- contextEntryDef.klass = List.class;
- return contextEntryDef;
- }
-
-
public String getName() {
return name;
}
@@ -67,32 +67,36 @@
return super.toString() + "<" + klass + ":" + name + ">";
}
- protected JAXXContextEntryDef(Class<O> klass) {
+ public JAXXContextEntryDef(Class<O> klass) {
this(null, klass);
}
- protected JAXXContextEntryDef(String name, Class<O> klass) {
+ @SuppressWarnings("unchecked")
+ public JAXXContextEntryDef(String name, Class<O> klass) {
if (klass == null) {
throw new IllegalArgumentException("class can not be null");
}
this.name = name;
+ if (List.class.isAssignableFrom(klass)) {
+ klass = (Class<O>) List.class;
+ }
this.klass = klass;
}
+//
+// @SuppressWarnings({"unchecked"})
+// protected static <O> Class<List<O>> castList() {
+// return (Class<List<O>>) Collections.emptyList().getClass();
+// }
- @SuppressWarnings({"unchecked"})
- protected static <O> Class<List<O>> castList() {
- return (Class<List<O>>) Collections.emptyList().getClass();
- }
-
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
- if (!(o instanceof JAXXContextEntryDef)) {
+ if (!(o instanceof JAXXContextEntryDef<?>)) {
return false;
}
- JAXXContextEntryDef that = (JAXXContextEntryDef) o;
+ JAXXContextEntryDef<?> that = (JAXXContextEntryDef<?>) o;
return klass.equals(that.klass) && !(name != null ? !name.equals(that.name) : that.name != null);
}
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2009-10-21 13:16:51 UTC (rev 1582)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2009-10-22 10:57:40 UTC (rev 1583)
@@ -2,6 +2,7 @@
import javax.swing.JTree;
import jaxx.runtime.JAXXContext;
+import jaxx.runtime.Util;
import jaxx.runtime.context.JAXXContextEntryDef;
/**
@@ -46,12 +47,12 @@
public NavigationTreeContextHelper(String prefix) {
this.prefix = prefix;
- treeContextEntry = JAXXContextEntryDef.newDef(prefix + "-tree", JTree.class);
- treeModelContextEntry = JAXXContextEntryDef.newDef(prefix + "-tree-model", NavigationTreeModel.class);
- treeHandlerContextEntry = JAXXContextEntryDef.newDef(prefix + "-tree-handler", NavigationTreeHandler.class);
- selectedBeanContextEntry = JAXXContextEntryDef.newDef(prefix + "-selected-bean", Object.class);
- selectedNodeContextEntry = JAXXContextEntryDef.newDef(prefix + "-selected-node", NavigationTreeNode.class);
- selectedPathContextEntry = JAXXContextEntryDef.newDef(prefix + "-selected-path", String.class);
+ treeContextEntry = Util.newContextEntryDef(prefix + "-tree", JTree.class);
+ treeModelContextEntry = Util.newContextEntryDef(prefix + "-tree-model", NavigationTreeModel.class);
+ treeHandlerContextEntry = Util.newContextEntryDef(prefix + "-tree-handler", NavigationTreeHandler.class);
+ selectedBeanContextEntry = Util.newContextEntryDef(prefix + "-selected-bean", Object.class);
+ selectedNodeContextEntry = Util.newContextEntryDef(prefix + "-selected-node", NavigationTreeNode.class);
+ selectedPathContextEntry = Util.newContextEntryDef(prefix + "-selected-path", String.class);
}
public String getPrefix() {
@@ -88,14 +89,6 @@
return r;
}
- public <T> T getSelectedBean(JAXXContext context, Class<T> type) {
- Object r = getSelectedBean(context);
- if (r != null && !type.isAssignableFrom(r.getClass())) {
- throw new IllegalStateException("required a object of type '" + type + "' but had '" + r.getClass() + "'");
- }
- return (T) r;
- }
-
public void setTreeModel(JAXXContext context, NavigationTreeModel model) {
getTreeModelContextEntry().setContextValue(context, model);
}
Modified: branches/jaxx-2.X/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2009-10-21 13:16:51 UTC (rev 1582)
+++ branches/jaxx-2.X/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2009-10-22 10:57:40 UTC (rev 1583)
@@ -1,17 +1,14 @@
package jaxx.runtime.swing.navigation;
-import jaxx.runtime.swing.navigation.NavigationTreeNode;
-import jaxx.runtime.swing.navigation.NavigationTreeModel;
-import jaxx.runtime.swing.navigation.NavigationTreeModelBuilder;
import jaxx.runtime.context.DefaultJAXXContext;
import jaxx.runtime.JAXXContext;
-import jaxx.runtime.context.JAXXContextEntryDef;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import jaxx.runtime.Util;
/**
* Test du model de navigation.
@@ -147,10 +144,10 @@
NavigationTreeNode sonSonNode;
NavigationTreeNode sonSonSonNode;
- builder.build(rootNode, (String) null, JAXXContextEntryDef.newDef("name", String.class), "name", null, null);
- builder.build(rootNode, (String) null, JAXXContextEntryDef.newDef("name2", String.class), "name2", null, null);
+ builder.build(rootNode, (String) null, Util.newContextEntryDef("name", String.class), "name", null, null);
+ builder.build(rootNode, (String) null, Util.newContextEntryDef("name2", String.class), "name2", null, null);
- sonNode = builder.build(rootNode, (String) null, JAXXContextEntryDef.newDef(Model.class), "model", null, null);
+ sonNode = builder.build(rootNode, (String) null, Util.newContextEntryDef(Model.class), "model", null, null);
builder.build(sonNode, (String) null, "../name", "name", null, null);
builder.build(sonNode, (String) null, "../integerValue", "integerValue", null, null);
@@ -269,7 +266,7 @@
NavigationTreeNode sonSonSonNode;
// first son is a list of models
- sonNode = builder.build(rootNode, (String) null, JAXXContextEntryDef.newListDef("models"), "models", null, null);
+ sonNode = builder.build(rootNode, (String) null, Util.newListContextEntryDef("models"), "models", null, null);
// first son son is a model
sonSonNode = builder.build(sonNode, (String) null, "..[1]", "0", null, null);
@@ -327,7 +324,7 @@
Object value;
value = model.getBean(contextPath);
- Assert.assertNotNull(value);
+ Assert.assertNotNull("could not find bean for path : " + contextPath, value);
Assert.assertEquals(expected, value);
}
1
0
r1582 - branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by tchemit@users.nuiton.org 21 Oct '09
by tchemit@users.nuiton.org 21 Oct '09
21 Oct '09
Author: tchemit
Date: 2009-10-21 15:16:51 +0200 (Wed, 21 Oct 2009)
New Revision: 1582
Modified:
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
Log:
do not make equals on class, prefer use method isAssignableFrom
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2009-10-21 12:56:13 UTC (rev 1581)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2009-10-21 13:16:51 UTC (rev 1582)
@@ -89,11 +89,11 @@
}
public <T> T getSelectedBean(JAXXContext context, Class<T> type) {
- Object r = getSelectedBeanContextEntry().getContextValue(context);
- if (type.equals(r.getClass())){
- return (T)getSelectedBeanContextEntry().getContextValue(context);
+ Object r = getSelectedBean(context);
+ if (r != null && !type.isAssignableFrom(r.getClass())) {
+ throw new IllegalStateException("required a object of type '" + type + "' but had '" + r.getClass() + "'");
}
- return null;
+ return (T) r;
}
public void setTreeModel(JAXXContext context, NavigationTreeModel model) {
1
0
r1581 - branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation
by tchemit@users.nuiton.org 21 Oct '09
by tchemit@users.nuiton.org 21 Oct '09
21 Oct '09
Author: tchemit
Date: 2009-10-21 14:56:13 +0200 (Wed, 21 Oct 2009)
New Revision: 1581
Modified:
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/BaseContent.jaxx
Log:
fix generics on List
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/BaseContent.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/BaseContent.jaxx 2009-10-21 12:54:56 UTC (rev 1580)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/BaseContent.jaxx 2009-10-21 12:56:13 UTC (rev 1581)
@@ -46,8 +46,8 @@
return "no content";
}
StringBuilder buffer = new StringBuilder();
- if (data instanceof java.util.List) {
- for (Object o : ((java.util.List)data)) {
+ if (data instanceof java.util.List<?>) {
+ for (Object o : ((java.util.List<?>)data)) {
buffer.append(o).append("\n");
}
} else {
1
0