From: Robert L. <rle...@us...> - 2007-02-14 12:27:12
|
Update of /cvsroot/ccmtools/ccmtools/src/ccmtools/parser/assembly/metamodel In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14714/src/ccmtools/parser/assembly/metamodel Modified Files: Module.java Assembly.java ModelElement.java Model.java Log Message: ccm assembly metamodel + Java generator Index: ModelElement.java =================================================================== RCS file: /cvsroot/ccmtools/ccmtools/src/ccmtools/parser/assembly/metamodel/ModelElement.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ModelElement.java 12 Feb 2007 16:01:13 -0000 1.3 --- ModelElement.java 14 Feb 2007 12:27:05 -0000 1.4 *************** *** 11,14 **** --- 11,15 ---- import java.io.PrintStream; + import java.util.Map; /** *************** *** 17,20 **** --- 18,23 ---- public abstract class ModelElement { + public static final String IDL_SCOPE = "::"; + protected String name_; *************** *** 22,31 **** { name_ = name; } public abstract void prettyPrint( PrintStream out, String offset ); ! protected Module parent_; ! /** * returns the parent Module of this element (or null) --- 25,36 ---- { name_ = name; + if (name.indexOf(IDL_SCOPE) >= 0) + throw new RuntimeException("scoped name!"); } public abstract void prettyPrint( PrintStream out, String offset ); ! protected Module parent_; ! /** * returns the parent Module of this element (or null) *************** *** 36,44 **** } /** * call this method after model creation * * @param parent namespace or null */ ! abstract void postProcessing( Module parent ); } --- 41,62 ---- } + public String getGlobalName() + { + if (parent_ != null) + { + return parent_.getGlobalName() + IDL_SCOPE + name_; + } + else + { + return IDL_SCOPE + name_; + } + } + /** * call this method after model creation * * @param parent namespace or null + * @param assemblies add all assemblies to that map */ ! abstract void postProcessing( Module parent, Map<String, Assembly> assemblies ); } Index: Model.java =================================================================== RCS file: /cvsroot/ccmtools/ccmtools/src/ccmtools/parser/assembly/metamodel/Model.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Model.java 12 Feb 2007 16:01:17 -0000 1.4 --- Model.java 14 Feb 2007 12:27:05 -0000 1.5 *************** *** 11,14 **** --- 11,15 ---- import java.io.PrintStream; + import java.util.HashMap; import java.util.Vector; *************** *** 28,31 **** --- 29,34 ---- } + private HashMap<String, Assembly> assemblies_; + /** * call this method after model creation *************** *** 33,39 **** public void postProcessing() { ! for (int i = 0; i < elements_.size(); ++i) { ! elements_.get(i).postProcessing(null); } } --- 36,43 ---- public void postProcessing() { ! assemblies_ = new HashMap<String, Assembly>(); ! for (ModelElement e : elements_) { ! e.postProcessing(null, assemblies_); } } *************** *** 46,53 **** public void prettyPrint( PrintStream out ) { ! for (int i = 0; i < elements_.size(); ++i) { ! elements_.get(i).prettyPrint(out, ""); } } } --- 50,77 ---- public void prettyPrint( PrintStream out ) { ! for (ModelElement e : elements_) { ! e.prettyPrint(out, ""); } } + + /** + * adds all elements of the give model to this model + */ + public void merge( Model m ) + { + elements_.addAll(m.elements_); + if (assemblies_ == null) + assemblies_ = new HashMap<String, Assembly>(m.assemblies_); + else + for (String key : m.assemblies_.keySet()) + { + if (assemblies_.containsKey(key)) + { + throw new RuntimeException("an assembly of type \"" + key + "\" already exists"); + } + Assembly a = m.assemblies_.get(key); + assemblies_.put(key, a); + } + } } Index: Module.java =================================================================== RCS file: /cvsroot/ccmtools/ccmtools/src/ccmtools/parser/assembly/metamodel/Module.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Module.java 12 Feb 2007 16:01:12 -0000 1.4 --- Module.java 14 Feb 2007 12:27:05 -0000 1.5 *************** *** 11,14 **** --- 11,15 ---- import java.io.PrintStream; + import java.util.Map; import java.util.Vector; *************** *** 26,35 **** } ! void postProcessing( Module parent ) { parent_ = parent; for (int i = 0; i < children_.size(); ++i) { ! children_.get(i).postProcessing(this); } } --- 27,36 ---- } ! void postProcessing( Module parent, Map<String, Assembly> assemblies ) { parent_ = parent; for (int i = 0; i < children_.size(); ++i) { ! children_.get(i).postProcessing(this, assemblies); } } Index: Assembly.java =================================================================== RCS file: /cvsroot/ccmtools/ccmtools/src/ccmtools/parser/assembly/metamodel/Assembly.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Assembly.java 12 Feb 2007 16:01:12 -0000 1.4 --- Assembly.java 14 Feb 2007 12:27:05 -0000 1.5 *************** *** 12,15 **** --- 12,16 ---- import java.io.PrintStream; import java.util.HashMap; + import java.util.Map; import java.util.Vector; *************** *** 19,30 **** public class Assembly extends ModelElement { ! private QualifiedName idl_name_; private Vector<AssemblyElement> elements_; ! public Assembly( String name, QualifiedName idl_name, Vector<AssemblyElement> elements ) { super(name); ! idl_name_ = idl_name; elements_ = elements; } --- 20,31 ---- public class Assembly extends ModelElement { ! private String opt_name_; private Vector<AssemblyElement> elements_; ! public Assembly( String name, String opt_name, Vector<AssemblyElement> elements ) { super(name); ! opt_name_ = opt_name; elements_ = elements; } *************** *** 32,39 **** private HashMap<String, Component> components_; ! void postProcessing( Module parent ) { parent_ = parent; ! idl_name_.postProcessing(parent); components_ = new HashMap<String, Component>(); for (int i = 0; i < elements_.size(); ++i) --- 33,45 ---- private HashMap<String, Component> components_; ! void postProcessing( Module parent, Map<String, Assembly> assemblies ) { parent_ = parent; ! String key = getGlobalName(); ! if (assemblies.containsKey(key)) ! { ! throw new RuntimeException("an assembly of type \"" + key + "\" already exists"); ! } ! assemblies.put(key, this); components_ = new HashMap<String, Component>(); for (int i = 0; i < elements_.size(); ++i) *************** *** 45,49 **** public void prettyPrint( PrintStream out, String offset ) { ! out.println(offset + "assembly " + name_ + " implements " + idl_name_ + " {"); for (int i = 0; i < elements_.size(); ++i) { --- 51,58 ---- public void prettyPrint( PrintStream out, String offset ) { ! out.print(offset + "assembly "); ! if (opt_name_ != null) ! out.print(opt_name_ + " "); ! out.println("implements " + name_ + " {"); for (int i = 0; i < elements_.size(); ++i) { |