001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.reporting.dataobjects;
043:
044: import java.io.File;
045: import java.io.FileOutputStream;
046: import java.io.OutputStreamWriter;
047: import java.util.logging.Level;
048: import java.util.logging.Logger;
049: import org.netbeans.modules.uml.core.metamodel.core.constructs.IExtend;
050: import org.netbeans.modules.uml.core.metamodel.core.constructs.IExtensionPoint;
051: import org.netbeans.modules.uml.core.metamodel.core.constructs.IInclude;
052: import org.netbeans.modules.uml.core.metamodel.core.constructs.IPartFacade;
053: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
054: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamedElement;
055: import org.netbeans.modules.uml.core.metamodel.infrastructure.IStructuredClassifier;
056: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IAttribute;
057: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
058: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IOperation;
059: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IParameter;
060: import org.netbeans.modules.uml.core.support.umlutils.ETList;
061: import org.openide.util.NbBundle;
062:
063: /**
064: *
065: * @author Sheryl
066: */
067: public class PartFacadeData extends ClassData {
068: private IPartFacade element;
069:
070: /** Creates a new instance of PartFacadeData */
071: public PartFacadeData() {
072: }
073:
074: public void setElement(IElement e) {
075: if (e instanceof IPartFacade)
076: this .element = (IPartFacade) e;
077: }
078:
079: public IPartFacade getElement() {
080: return element;
081: }
082:
083: public boolean toReport(File file) {
084: if (getElement() == null)
085: return false;
086:
087: ETList<IExtend> extendsList = getElement().getExtends();
088: ETList<IInclude> includesList = getElement().getIncludes();
089: ETList<IExtensionPoint> points = getElement()
090: .getExtensionPoints();
091: ETList<IStructuredClassifier> contexts = getElement()
092: .getRoleContexts();
093:
094: boolean result = false;
095: try {
096: FileOutputStream fo = new FileOutputStream(file);
097: OutputStreamWriter out = new OutputStreamWriter(fo,
098: ENCODING);
099: String doc = "";
100:
101: out.write(getHTMLHeader());
102: out.write("<BODY BGCOLOR=\"white\">\r\n");
103: out.write(getNavBar());
104: out.write("<HR>\r\n");
105: out.write("<H2>\r\n");
106: out.write("<FONT SIZE=\"-1\">" + getOwningPackageName()
107: + "</FONT>\r\n");
108: out.write("<BR>\r\n");
109: out.write(NbBundle.getMessage(PartFacadeData.class,
110: "ElementType_"
111: + getElement().getExpandedElementType())
112: + " "
113: + ((INamedElement) getElement()).getName()
114: + "</H2>\r\n");
115:
116: out.write("<DL>\r\n");
117: out.write("<DT>" + getVisibility(getElement()) + " "
118: + getElementType().toLowerCase() + " <B>"
119: + getElement().getName() + "</B></DT>");
120: if (extendsList.size() > 0) {
121: out.write("<DT>"
122: + NbBundle.getMessage(PartFacadeData.class,
123: "extends") + " ");
124: for (int i = 0; i < extendsList.size(); i++) {
125: IExtend extend = extendsList.get(i);
126: out.write("<A HREF=\""
127: + getLinkTo(extend.getBase())
128: + "\" title=\"" + getElementType() + " in"
129: + getOwningPackageName() + "\">"
130: + extend.getBase().getName() + "</A>");
131: if (i < extendsList.size() - 1)
132: out.write(", ");
133: }
134: }
135:
136: if (includesList.size() > 0) {
137: out.write("<DT>"
138: + NbBundle.getMessage(PartFacadeData.class,
139: "includes") + " ");
140: for (int i = 0; i < includesList.size(); i++) {
141: IInclude include = includesList.get(i);
142: if (include == null
143: || include.getAddition() == null) {
144: Logger
145: .getLogger(
146: PartFacadeData.class.getName())
147: .log(
148: Level.WARNING,
149: NbBundle
150: .getMessage(
151: LifelineData.class,
152: "MSG_InvalidPartFacade",
153: getElementType(),
154: getElementName()));
155: continue;
156: }
157:
158: if (include.getOwningPackage() != null) {
159: out.write("<A HREF=\""
160: + getLinkTo(include.getAddition())
161: + "\" title=\""
162: + getElementType()
163: + " in "
164: + include.getOwningPackage()
165: .getFullyQualifiedName(false)
166: + "\">"
167: + include.getAddition().getName()
168: + "</A>");
169: } else {
170: out.write(include.getAddition().getName());
171:
172: Logger
173: .getLogger(
174: PartFacadeData.class.getName())
175: .log(
176: Level.WARNING,
177: NbBundle
178: .getMessage(
179: LifelineData.class,
180: "MSG_InvalidPackage",
181: include
182: .getAddition()
183: .getElementType(),
184: include
185: .getAddition()
186: .getName()));
187: }
188: if (i < includesList.size() - 1)
189: out.write(", ");
190: }
191: }
192:
193: IClassifier classifier = getElement()
194: .getFeaturingClassifier();
195: if (classifier == null) {
196: // Logger.getLogger(PartFacadeData.class.getName()).
197: // log(Level.WARNING,
198: // NbBundle.getMessage(LifelineData.class,
199: // "MSG_InvalidPartFacade", getElementType(), getElementName()));
200: } else {
201: if (classifier.getOwningPackage() != null) {
202: out.write("<DT>"
203: + NbBundle.getMessage(PartFacadeData.class,
204: "features")
205: + " "
206: + "<A HREF=\""
207: + getLinkTo(classifier)
208: + "\" title=\""
209: + getElement().getExpandedElementType()
210: + " in "
211: + classifier.getOwningPackage()
212: .getFullyQualifiedName(false)
213: + "\">" + classifier.getName() + "</A>");
214: } else {
215: out.write("<DT>"
216: + NbBundle.getMessage(PartFacadeData.class,
217: "features") + " "
218: + classifier.getName());
219: Logger
220: .getLogger(PartFacadeData.class.getName())
221: .log(
222: Level.WARNING,
223: NbBundle
224: .getMessage(
225: LifelineData.class,
226: "MSG_InvalidPackage",
227: classifier
228: .getElementType(),
229: classifier
230: .getName()));
231: }
232: }
233: out.write("</DL>\r\n\r\n");
234:
235: out.write(getDependencies());
236: out.write(getAssociations());
237:
238: out.write(getEnclosingDiagrams());
239:
240: out.write(getDocumentation());
241:
242: // property summary
243:
244: out.write(getProperties());
245:
246: // attribute summary
247: ETList<IAttribute> attrs = getElement().getAttributes();
248: IAttribute attr;
249: IClassifier type;
250: if (attrs.size() > 0) {
251: out
252: .write("<!-- =========== ATTRIBUTE SUMMARY =========== -->\r\n");
253: out.write(getSummaryHeader("attribute_summary",
254: NbBundle.getMessage(ClassData.class,
255: "Attribute_Summary")));
256:
257: for (int i = 0; i < attrs.size(); i++) {
258: attr = attrs.get(i);
259: type = attr.getType();
260: out
261: .write("<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">\r\n");
262: out
263: .write("<TD ALIGN=\"right\" VALIGN=\"top\" WIDTH=\"1%\"><FONT SIZE=\"-1\">\r\n");
264: if (type != null)
265: out.write("<CODE>" + "<A HREF=\""
266: + getLinkTo(type) + "\">"
267: + type.getName()
268: + "</A></CODE></FONT></TD>\r\n");
269: else {
270: out
271: .write("<CODE> </CODE></FONT></TD>\r\n");
272: Logger
273: .getLogger(
274: PartFacadeData.class.getName())
275: .log(
276: Level.WARNING,
277: NbBundle.getMessage(
278: ClassData.class,
279: "MSG_InvalidType",
280: attr.getElementType(),
281: attr.getName())); // NOI18N
282: }
283: out.write("<TD><CODE><B><A HREF=\"#"
284: + attr.getName() + "\">" + attr.getName()
285: + "</A></B></CODE>\r\n");
286: out.write("<BR>\r\n");
287: out
288: .write(" "
289: + getBriefDocumentation(attr
290: .getDocumentation())
291: + "</TD>\r\n</TR>\r\n");
292: }
293: out.write("</TABLE>\r\n \r\n");
294: }
295:
296: // constructor summary
297:
298: IOperation[] constructors = getConstructors();
299: if (constructors.length > 0) {
300: out
301: .write("<!-- =========== CONSTRUCTOR SUMMARY =========== -->\r\n\r\n");
302: out.write(getSummaryHeader("constructor_summary",
303: NbBundle.getMessage(ClassData.class,
304: "Constructor_Summary")));
305: out.write(getOperationSummary(constructors));
306: }
307:
308: // operation summary
309:
310: IOperation[] ops = getOperations();
311: IOperation op;
312: IParameter returnType;
313: if (ops.length > 0) {
314: out
315: .write("<!-- =========== OPERATION SUMMARY =========== -->\r\n");
316: out.write(getSummaryHeader("operation_summary",
317: NbBundle.getMessage(ClassData.class,
318: "Operation_Summary")));
319:
320: out.write(getOperationSummary(ops));
321: }
322:
323: // stereotype summary
324: out.write(getStereoTypesSummary());
325:
326: // tagged value summary
327: out.write(getTaggedValueSummary());
328:
329: // constraint summary
330: out.write(getConstraintsSummary());
331:
332: // extension point summary
333: if (points.size() > 0) {
334: out
335: .write("<!-- =========== EXTENSION POINT SUMMARY =========== -->\r\n");
336: out.write(getSummaryHeader("extension_point_summary",
337: NbBundle.getMessage(PartFacadeData.class,
338: "Extension_Point_Summary")));
339:
340: for (int i = 0; i < points.size(); i++) {
341: IExtensionPoint point = points.get(i);
342: doc = point.getDocumentation();
343: if (doc == null || doc.trim().equals(""))
344: doc = " ";
345: out
346: .write("<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">\r\n");
347: out.write("<TD WIDTH=\"15%\"><B>" + point.getName()
348: + "</B></TD>\r\n");
349: out.write("<TD>" + doc + "</TD>\r\n");
350: out.write("</TR>\r\n");
351: }
352: out.write("</TABLE>\r\n \r\n<P>\r\n");
353: }
354:
355: // attribute detail
356:
357: if (attrs.size() > 0) {
358: out
359: .write("<!-- =========== ATTRIBUTE DETAIL =========== -->\r\n");
360: out.write(getDetailHeader("attribute_detail",
361: NbBundle.getMessage(ClassData.class,
362: "Attribute_Detail")));
363:
364: for (int i = 0; i < attrs.size(); i++) {
365: attr = attrs.get(i);
366: type = attr.getType();
367:
368: out.write("<A NAME=\"" + attr.getName()
369: + "\"></A><H3>" + attr.getName()
370: + "</H3>\r\n");
371: out.write("" + formatAttribute(attr) + "<B>"
372: + attr.getName() + "</B>");
373: out.write("<DL>\r\n");
374:
375: out.write("<DD>" + attr.getDocumentation()
376: + "\r\n<P>\r\n</DD>\r\n</DL>\r\n");
377:
378: if (i < attrs.size() - 1)
379: out.write("<HR>\r\n\r\n");
380: else
381: out.write("\r\n");
382: }
383: }
384:
385: // constructor detail
386:
387: if (constructors.length > 0) {
388: out
389: .write("<!-- =========== CONSTRUCTOR DETAIL =========== -->\r\n\r\n");
390: out.write(getDetailHeader("constructor_detail",
391: NbBundle.getMessage(ClassData.class,
392: "Constructor_Detail")));
393:
394: out.write(getOperationDetail(constructors));
395: }
396: // operation detail
397:
398: if (ops.length > 0) {
399: out
400: .write("<!-- =========== OPERATION DETAIL =========== -->\r\n\r\n");
401: out.write(getDetailHeader("operationr_detail",
402: NbBundle.getMessage(ClassData.class,
403: "Operation_Detail")));
404:
405: out.write(getOperationDetail(ops));
406: }
407:
408: out.write("<HR>\r\n");
409: out.write(getNavBar());
410: out.write("</BODY>\r\n</HTML>");
411: out.close();
412: result = true;
413:
414: } catch (Exception e) {
415: Logger.getLogger(ElementDataObject.class.getName()).log(
416: Level.SEVERE,
417: getElement().getElementType() + " - "
418: + getElement().getNameWithAlias(), e);
419: result = false;
420: }
421: return result;
422:
423: }
424: }
|