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: package org.netbeans.modules.visualweb.insync.faces;
042:
043: import org.netbeans.modules.visualweb.insync.UndoEvent;
044: import org.netbeans.modules.visualweb.insync.beans.BeanStructureScanner;
045: import org.netbeans.modules.visualweb.insync.beans.BeansUnit;
046: import org.netbeans.modules.visualweb.insync.java.MethodInfo;
047: import java.lang.reflect.Modifier;
048: import java.util.List;
049: import java.util.ListIterator;
050: import org.netbeans.modules.visualweb.insync.java.Statement;
051: import org.openide.util.NbBundle;
052:
053: public class ThresherFacesBeanStructureScanner extends
054: BeanStructureScanner {
055: public static String PROP_INITMETHOD = "_init";
056: public static String INITMETHOD = "init";
057: public static String DESTROYMETHOD = "destroy";
058:
059: protected MethodInfo initInfo = new MethodInfo(INITMETHOD,
060: Modifier.PUBLIC, Void.TYPE, getInitMethodComment(),
061: ENSURE_INITBLOCK);
062:
063: public ThresherFacesBeanStructureScanner(BeansUnit unit) {
064: super (unit);
065: ctorInfo.setComment(getConstructorComment());
066: ctorInfo.setEnsureMethodName(null);
067: destroyInfo = new MethodInfo(DESTROYMETHOD);
068: destroyInfo.setComment(getDestroyMethodComment());
069: propertiesInitInfo = new MethodInfo(PROP_INITMETHOD,
070: Modifier.PRIVATE, Void.TYPE,
071: getComment("COMMENT_PropInitMethodComment"), null,
072: "Exception");
073: }
074:
075: public List<Statement> getPropertiesInitStatements() {
076: List<Statement> stmts = ctorInfo.getMethod()
077: .getPropertySetStatements();
078: stmts.addAll(propertiesInitInfo.getMethod()
079: .getPropertySetStatements());
080: return stmts;
081: }
082:
083: protected void ensureInitBlock(MethodInfo mi) {
084: UndoEvent event = null;
085: try {
086: String eventName = NbBundle.getMessage(
087: BeanStructureScanner.class, "EnsureInitBlock"); //NOI18N
088: event = beansUnit.getModel().writeLock(eventName);
089: if (mi.getMethod().hasInitBlock()) {
090: return;
091: }
092: String bodyText = "// "
093: + getComment("COMMENT_InitSuperCall")
094: + "\n"
095: + "super.init();\n"
096: + "// "
097: + getComment("COMMENT_UserPreInit")
098: + "\n\n"
099: + "// <editor-fold defaultstate=\"collapsed\" desc=\""
100: + getComment("COMMENT_InitDescription")
101: + "\">\n"
102: + "// "
103: + getComment("COMMENT_PropInit")
104: + "\n"
105: + "try {\n"
106: + "_init();\n"
107: + "} catch (Exception e) {\n"
108: + "log(\"Page1 Initialization Failure\", e);\n"
109: + "throw e instanceof FacesException ? (FacesException) e: new FacesException(e);\n"
110: + "}\n\n" + "// </editor-fold>\n" + "// "
111: + getComment("COMMENT_UserPostInit");
112: mi.getMethod().replaceBody(bodyText);
113: javaUnit.ensureImport("javax.faces.FacesException");
114: } finally {
115: if (event != null) {
116: beansUnit.getModel().writeUnlock(event);
117: }
118: }
119: }
120:
121: public String getConstructorComment() {
122: return null;
123: }
124:
125: public String getDestroyMethodComment() {
126: return null;
127: }
128:
129: public String getInitMethodComment() {
130: return null;
131: }
132:
133: public String getComment(String id) {
134: return NbBundle.getMessage(
135: ThresherFacesBeanStructureScanner.class, id);
136: }
137: }
|