svnno****@sourc*****
svnno****@sourc*****
2008年 9月 24日 (水) 01:45:28 JST
Revision: 1948 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=jiemamy&view=rev&rev=1948 Author: shin1 Date: 2008-09-24 01:45:28 +0900 (Wed, 24 Sep 2008) Log Message: ----------- [CORE-76]下記の2点を前提で作業。 spec.coreと、spec-coreに依存したspec.event、のふたつに依存する。 spec.eventにはObservableCollection系の実装、ObservableChangeEventも含む。 Modified Paths: -------------- sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/.classpath sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/JiemamyDocletMain.launch sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/CollectionProperty.java sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/JiemamyModelDoclet.java sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/resources/ChangeSupport.vm Added Paths: ----------- sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/resources/ChangeSupportImpl.vm -------------- next part -------------- Modified: sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/.classpath =================================================================== --- sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/.classpath 2008-09-23 13:12:54 UTC (rev 1947) +++ sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/.classpath 2008-09-23 16:45:28 UTC (rev 1948) @@ -14,6 +14,7 @@ </classpathentry> <classpathentry kind="var" path="M2_REPO/oro/oro/2.0.8/oro-2.0.8.jar" sourcepath="M2_REPO/oro/oro/2.0.8/oro-2.0.8-sources.jar"/> <classpathentry kind="var" path="M2_REPO/org/apache/velocity/velocity/1.5/velocity-1.5.jar"/> - <classpathentry combineaccessrules="false" kind="src" path="/org.jiemamy.core"/> + <classpathentry combineaccessrules="false" kind="src" path="/org.jiemamy.spec.core"/> + <classpathentry combineaccessrules="false" kind="src" path="/org.jiemamy.spec.event"/> <classpathentry kind="output" path="target/classes"/> </classpath> Modified: sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/JiemamyDocletMain.launch =================================================================== --- sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/JiemamyDocletMain.launch 2008-09-23 13:12:54 UTC (rev 1947) +++ sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/JiemamyDocletMain.launch 2008-09-23 16:45:28 UTC (rev 1948) @@ -7,7 +7,10 @@ <listEntry value="4"/> </listAttribute> <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> +<listAttribute key="org.eclipse.debug.ui.favoriteGroups"> +<listEntry value="org.eclipse.debug.ui.launchGroup.run"/> +</listAttribute> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.sun.tools.javadoc.Main"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-doclet org.jiemamy.core.eventcodegen.JiemamyModelDoclet -sourcepath ../org.jiemamy.core/src/main/java -subpackages org.jiemamy.core.model -private"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-doclet org.jiemamy.core.eventcodegen.JiemamyModelDoclet -sourcepath ../org.jiemamy.spec.core/src/main/java -subpackages org.jiemamy.spec.model -private"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.jiemamy.core.eventcodegen"/> </launchConfiguration> Modified: sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/CollectionProperty.java =================================================================== --- sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/CollectionProperty.java 2008-09-23 13:12:54 UTC (rev 1947) +++ sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/CollectionProperty.java 2008-09-23 16:45:28 UTC (rev 1948) @@ -4,9 +4,9 @@ import java.util.Map; import java.util.Set; -import org.jiemamy.core.event.collectionimpl.ObservableList; -import org.jiemamy.core.event.collectionimpl.ObservableMap; -import org.jiemamy.core.event.collectionimpl.ObservableSet; +import org.jiemamy.spec.event.collectionimpl.ObservableList; +import org.jiemamy.spec.event.collectionimpl.ObservableMap; +import org.jiemamy.spec.event.collectionimpl.ObservableSet; public class CollectionProperty { private String name; Modified: sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/JiemamyModelDoclet.java =================================================================== --- sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/JiemamyModelDoclet.java 2008-09-23 13:12:54 UTC (rev 1947) +++ sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/JiemamyModelDoclet.java 2008-09-23 16:45:28 UTC (rev 1948) @@ -32,9 +32,10 @@ public class JiemamyModelDoclet extends Doclet { public List<JiemamyModel> model; public Map<Class<?>, CollectionProperty> collectionProperties = new HashMap<Class<?>, CollectionProperty>(); - // public static final String OUTPUTDIR = "target/"; - // public static final String OUTPUTDIR = "src/main/java/"; - public static final String OUTPUTDIR = "../org.jiemamy.core/src/main/java/"; + public static final String OUTPUTDIR_SPECS = "src/main/java/"; + public static final String OUTPUTDIR_IMPLEMENTS = "src/main/java/"; +// public static final String OUTPUTDIR_IMPLEMENTS = "../org.jiemamy.core/src/main/java/"; +// public static final String OUTPUTDIR_SPECS = "../org.jiemamy.spec.event/src/main/java/"; public static LanguageVersion languageVersion() { return LanguageVersion.JAVA_1_5; @@ -83,8 +84,6 @@ try { try { Class<?> clazz = Class.forName(classDoc.qualifiedName()); - // Instance化出来ないものはInstantialtionExceptionを発生させて弾く。 - clazz.newInstance(); // JiemamyModelのサブクラスでないものはClassCastExceptionを発生させて弾く。 clazz.asSubclass(JiemamyModel.class); processModel(classDoc); @@ -115,9 +114,9 @@ List<String> importClasses = new ArrayList<String>(); addImportClasses(importClasses, classDoc.qualifiedTypeName()); addImportClasses(importClasses, - "org.jiemamy.core.event.ModelChangeListener"); + "org.jiemamy.spec.util.ModelChangeListener"); addImportClasses(importClasses, - "org.jiemamy.core.event.ObservableCollectionChangeEvent"); + "org.jiemamy.spec.event.ObservableCollectionChangeEvent"); List<CollectionProperty> properties = new ArrayList<CollectionProperty>(); FieldDoc[] fields = classDoc.fields(); for (FieldDoc fieldDoc : fields) { @@ -155,11 +154,17 @@ // Templateからjavaファイルを生成する。 try { String packageName = getPackageName(classDoc).replaceAll( - "org.jiemamy.core", "org.jiemamy.core.event"); - File dir = new File(OUTPUTDIR + packageName.replaceAll("\\.", "/")); - if (!dir.exists()) { - dir.mkdirs(); + "org.jiemamy.spec", "org.jiemamy.spec.event"); + File dirForSpec = new File(OUTPUTDIR_SPECS + + packageName.replaceAll("\\.", "/")); + if (!dirForSpec.exists()) { + dirForSpec.mkdirs(); } + File dirForImpl = new File(OUTPUTDIR_IMPLEMENTS + + packageName.replaceAll("\\.", "/")); + if (!dirForSpec.exists()) { + dirForSpec.mkdirs(); + } VelocityContext velocityContext = new VelocityContext(); velocityContext.put("package", packageName); velocityContext.put("importClasses", importClasses); @@ -172,7 +177,7 @@ // ChangeListenerの生成 Template listenerTemplate = Velocity .getTemplate("ChangeListener.vm"); - File file = new File(dir.getAbsolutePath() + "/" + File file = new File(dirForSpec.getAbsolutePath() + "/" + classDoc.name().toString() + "ChangeListener.java"); System.out.println(file.getAbsolutePath()); Writer writer = new FileWriter(file); @@ -184,10 +189,10 @@ addImportClasses(importClasses, "java.util.List"); addImportClasses(importClasses, "java.util.ArrayList"); addImportClasses(importClasses, - "org.jiemamy.core.event.ModelChangeEvent"); + "org.jiemamy.spec.util.ModelChangeEvent"); if (properties.size() > 0) { importClasses - .add("org.jiemamy.core.event.ObservableCollectionChangeListener"); + .add("org.jiemamy.spec.event.ObservableCollectionChangeListener"); } for (CollectionProperty property : properties) { addImportClasses(importClasses, property @@ -195,13 +200,37 @@ } Collections.sort(importClasses); Template supportTemplate = Velocity.getTemplate("ChangeSupport.vm"); - file = new File(dir.getAbsolutePath() + "/" + file = new File(dirForSpec.getAbsolutePath() + "/" + classDoc.name().toString() + "ChangeSupport.java"); System.out.println(file.getAbsolutePath()); writer = new FileWriter(file); supportTemplate.merge(velocityContext, writer); writer.flush(); writer.close(); + + // ChangeSupportImplの生成 + addImportClasses(importClasses, "java.util.List"); + addImportClasses(importClasses, "java.util.ArrayList"); + addImportClasses(importClasses, + "org.jiemamy.spec.util.ModelChangeEvent"); + if (properties.size() > 0) { + importClasses + .add("org.jiemamy.spec.event.ObservableCollectionChangeListener"); + } + for (CollectionProperty property : properties) { + addImportClasses(importClasses, property + .getObservableCollectionClassName()); + } + Collections.sort(importClasses); + Template supportImplTemplate = Velocity + .getTemplate("ChangeSupportImpl.vm"); + file = new File(dirForImpl.getAbsolutePath() + "/" + + classDoc.name().toString() + "ChangeSupportImpl.java"); + System.out.println(file.getAbsolutePath()); + writer = new FileWriter(file); + supportImplTemplate.merge(velocityContext, writer); + writer.flush(); + writer.close(); } catch (Exception ex) { ex.printStackTrace(); } Modified: sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/resources/ChangeSupport.vm =================================================================== --- sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/resources/ChangeSupport.vm 2008-09-23 13:12:54 UTC (rev 1947) +++ sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/resources/ChangeSupport.vm 2008-09-23 16:45:28 UTC (rev 1948) @@ -27,68 +27,15 @@ * * @author shin1ogawa */ -public class ${modelClassName}ChangeSupport { +public interface ${modelClassName}ChangeSupport { - /** ${modelClassName}自身のEventを監視するListenerのリスト */ - private List<${modelClassName}ChangeListener> listeners = new ArrayList<${modelClassName}ChangeListener>(); - -#foreach($property in $properties) - - /** - * ${property.name}のリストを監視するListener - * - * @see ObservableCollectionChangeListener - * @see #fire${property.nameUpper}CollectionChangeEvent(ObservableCollectionChangeEvent) - */ - private ObservableCollectionChangeListener<${property.collectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>, ${property.elementClassSimpleName}> ${property.name}CollectionChangeListener = - new ObservableCollectionChangeListener<${property.collectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>, ${property.elementClassSimpleName}>() { - - /** - * {@inheritDoc} - */ - public void collectionChanged(ObservableCollectionChangeEvent<${property.collectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>, ${property.elementClassSimpleName}> event) { - fire${property.nameUpper}CollectionChangeEvent(event); - } - }; -#end - /** - * ${modelClassName}の属性の変更Eventを処理するListener - * - * @see #fireModelChange(ModelChangeEvent) - */ - private ModelChangeListener ${modelClassNameLower}ChangeListener = new ModelChangeListener() { - - /** - * {@inheritDoc} - */ - public void modelChanged(ModelChangeEvent event) { - fireModelChange(event); - } - }; - - /** - * コンストラクタ。 - * - * @param source {@link ${modelClassName}} - * @category instance creation - */ - public ${modelClassName}ChangeSupport(${modelClassName} source) { - source.addModelChangeListener(${modelClassNameLower}ChangeListener); -#foreach($property in $properties) - ((${property.observableCollectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>) source.get${property.nameUpper}()).addListener(${property.name}CollectionChangeListener); -#end - } - - /** * ${modelClassName}自身のEventを監視するListenerを追加する。 * * @param l {@link ${modelClassName}ChangeListener} * @see #remove${modelClassName}ChangeListener(${modelClassName}ChangeListener) */ - public void add${modelClassName}ChangeListener(${modelClassName}ChangeListener l) { - listeners.add(l); - } + void add${modelClassName}ChangeListener(${modelClassName}ChangeListener l); #foreach($property in $properties) /** @@ -96,32 +43,15 @@ * * @param event {@link ObservableCollectionChangeEvent} */ - public void fire${property.nameUpper}CollectionChangeEvent( - ObservableCollectionChangeEvent<${property.collectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>, ${property.elementClassSimpleName}> event) { - for (${modelClassName}ChangeListener l : listeners) { - l.${property.nameSingle}CollectionChange(event); - } - } + void fire${property.nameUpper}CollectionChangeEvent( + ObservableCollectionChangeEvent<${property.collectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>, ${property.elementClassSimpleName}> event); #end /** - * ${modelClassName}自身を監視するListenerに通知されたEventを${modelClassName}の監視Listenerへ通知する。 - * - * @param event {@link ModelChangeEvent} - */ - public void fireModelChange(ModelChangeEvent event) { - for (${modelClassName}ChangeListener l : listeners) { - l.modelChanged(event); - } - } - - /** * ${modelClassName}自身のEventを監視するListenerを削除する。 * * @param l {@link ${modelClassName}ChangeListener} * @see #add${modelClassName}ChangeListener(${modelClassName}ChangeListener) */ - public void remove${modelClassName}ChangeListener(${modelClassName}ChangeListener l) { - listeners.remove(l); - } + void remove${modelClassName}ChangeListener(${modelClassName}ChangeListener l); } Added: sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/resources/ChangeSupportImpl.vm =================================================================== --- sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/resources/ChangeSupportImpl.vm (rev 0) +++ sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/resources/ChangeSupportImpl.vm 2008-09-23 16:45:28 UTC (rev 1948) @@ -0,0 +1,127 @@ +/* + * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. + * Created on 2008/07/02 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package ${package}; + +#foreach($importClass in $importClasses) +import $importClass; +#end + +/** + * Event関連の処理をModel内に直接記述するとModelのSourceの可読性が低くなるため、${modelClassName}からそれらを引き受ける。 + * + * @author shin1ogawa + */ +public class ${modelClassName}ChangeSupportImpl implements ${modelClassName}ChangeSupport { + + /** ${modelClassName}自身のEventを監視するListenerのリスト */ + private List<${modelClassName}ChangeListener> listeners = new ArrayList<${modelClassName}ChangeListener>(); + +#foreach($property in $properties) + + /** + * ${property.name}のリストを監視するListener + * + * @see ObservableCollectionChangeListener + * @see #fire${property.nameUpper}CollectionChangeEvent(ObservableCollectionChangeEvent) + */ + private ObservableCollectionChangeListener<${property.collectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>, ${property.elementClassSimpleName}> ${property.name}CollectionChangeListener = + new ObservableCollectionChangeListener<${property.collectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>, ${property.elementClassSimpleName}>() { + + /** + * {@inheritDoc} + */ + public void collectionChanged(ObservableCollectionChangeEvent<${property.collectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>, ${property.elementClassSimpleName}> event) { + fire${property.nameUpper}CollectionChangeEvent(event); + } + }; +#end + + /** + * ${modelClassName}の属性の変更Eventを処理するListener + * + * @see #fireModelChange(ModelChangeEvent) + */ + private ModelChangeListener ${modelClassNameLower}ChangeListener = new ModelChangeListener() { + + /** + * {@inheritDoc} + */ + public void modelChanged(ModelChangeEvent event) { + fireModelChange(event); + } + }; + + /** + * コンストラクタ。 + * + * @param source {@link ${modelClassName}} + * @category instance creation + */ + public ${modelClassName}ChangeSupportImpl(${modelClassName} source) { + source.addModelChangeListener(${modelClassNameLower}ChangeListener); +#foreach($property in $properties) + ((${property.observableCollectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>) source.get${property.nameUpper}()).addListener(${property.name}CollectionChangeListener); +#end + } + + /** + * ${modelClassName}自身のEventを監視するListenerを追加する。 + * + * @param l {@link ${modelClassName}ChangeListener} + * @see #remove${modelClassName}ChangeListener(${modelClassName}ChangeListener) + */ + public void add${modelClassName}ChangeListener(${modelClassName}ChangeListener l) { + listeners.add(l); + } + +#foreach($property in $properties) + /** + * ${property.name}のcollectionを監視するListenerに通知されたEventを${modelClassName}の監視Listenerへ通知する。 + * + * @param event {@link ObservableCollectionChangeEvent} + */ + public void fire${property.nameUpper}CollectionChangeEvent( + ObservableCollectionChangeEvent<${property.collectionClassSimpleName}<#if(${property.map} != false)${property.mapKeyClassSimpleName}, #end${property.elementClassSimpleName}>, ${property.elementClassSimpleName}> event) { + for (${modelClassName}ChangeListener l : listeners) { + l.${property.nameSingle}CollectionChange(event); + } + } +#end + + /** + * ${modelClassName}自身を監視するListenerに通知されたEventを${modelClassName}の監視Listenerへ通知する。 + * + * @param event {@link ModelChangeEvent} + */ + public void fireModelChange(ModelChangeEvent event) { + for (${modelClassName}ChangeListener l : listeners) { + l.modelChanged(event); + } + } + + /** + * ${modelClassName}自身のEventを監視するListenerを削除する。 + * + * @param l {@link ${modelClassName}ChangeListener} + * @see #add${modelClassName}ChangeListener(${modelClassName}ChangeListener) + */ + public void remove${modelClassName}ChangeListener(${modelClassName}ChangeListener l) { + listeners.remove(l); + } +}