001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010:
011: package de.uka.ilkd.key.casetool.patternimplementor.patterns;
012:
013: import de.uka.ilkd.key.casetool.patternimplementor.*;
014:
015: public class Composite implements AbstractPatternImplementor {
016: private PIParameterGroup composite;
017: private ConstraintMechanism constraintMechanism;
018:
019: public PIParameterGroup getParameters() {
020: if (composite == null) {
021: createParameters();
022: }
023:
024: return composite;
025: }
026:
027: /*public AbstractFactory()
028: {
029:
030: createParameters();
031: }*/
032: protected void createParameters() {
033: composite = new PIParameterGroup("Composite", "Composite");
034:
035: //param1 = internal name, param2 = name, param3 = value (i.e.what gets
036: //returned from PIParameter::getValue())
037: PIParameterString c_class = new PIParameterString(
038: "Composite_class", "Composite", "Composite");
039: PIParameterString children_attr = new PIParameterString(
040: "children_attribute", "Children attribute", "children");
041:
042: PIParameterString component = new PIParameterString(
043: "Component", "Component", "Component");
044: PIParameterString leaf = new PIParameterMultiString("Leaf",
045: "Leaf", "Leaf");
046:
047: composite.add(component);
048: composite.add(leaf);
049: composite.add(c_class);
050: composite.add(children_attr);
051: constraintMechanism = new ConstraintMechanism(
052: "Composite.constraints", composite, this );
053:
054: /*System.out.println("abstractFactory {");
055: System.out.println(abstractFactory);
056: System.out.println("}");*/
057: }
058:
059: /*public void createAbstractFactoryDialog() {
060: JDialog jd = new JDialog();
061: jd.setContentPane(new PIParameterGUIGroup(abstractFactory));
062: jd.pack();
063: jd.setVisible(true);
064: }*/
065: private SourceCode createComponent() {
066: String comp = composite.get("Component").getValue();
067:
068: SourceCode source = new SourceCode();
069:
070: source.beginClass(comp);
071: source.add("/**");
072: source.add(constraintMechanism.getConstraints(" * ",
073: "Component", comp));
074: source.add(" */");
075: source.add("public class " + comp + " {");
076: source.add("\tpublic void add(" + comp + " c) {}");
077: source.add("}");
078:
079: return source;
080: }
081:
082: private SourceCode createComposite() {
083: String component = composite.get("Component").getValue();
084: String comp = composite.get("Composite_class").getValue();
085: String children = composite.get("children_attribute")
086: .getValue();
087:
088: SourceCode source = new SourceCode();
089:
090: source.beginClass(comp);
091: source.add("/**");
092: source.add(constraintMechanism.getConstraints(" * ",
093: "Composite", comp));
094: source.add(" */");
095: source.add("public class " + comp + " extends " + component
096: + " {");
097: source.add("\tpublic void add(" + component + " c) {}");
098: source.add("\t/**");
099: source.add("\t * @supplierCardinality 1..*");
100: source.add("\t * @supplierRole " + children);
101: source.add("\t * @supplierQualifier {ordered}");
102: source.add("\t */");
103: source.add("\tprivate " + component + " lnk" + component + ";");
104: source.add("}");
105:
106: return source; //classes;
107: }
108:
109: private SourceCode createLeaf() {
110: String component = composite.get("Component").getValue();
111: String leaf = composite.get("Leaf").getValue();
112:
113: SourceCode source = new SourceCode();
114:
115: source.beginClass(leaf);
116: source.add("/**");
117: source.add(constraintMechanism.getConstraints(" * ", "Leaf",
118: leaf));
119: source.add(" */");
120: source.add("public class " + leaf + " extends " + component
121: + " {");
122: source.add("\tpublic void add(" + component + " c) {}");
123: source.add("}");
124:
125: return source;
126: }
127:
128: public SourceCode getImplementation() {
129: if (composite == null) {
130: System.err
131: .println("ERROR - AbstractFactory,getImplementor : abstractFactory == null");
132:
133: return null;
134: }
135:
136: SourceCode code = new SourceCode();
137: code.add(createComponent());
138: code.add(createComposite());
139: code.add(createLeaf());
140:
141: return code;
142: }
143:
144: public String getName() {
145: return "Creational Patterns:Composite";
146: }
147: }
|