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.compapp.javaee.sunresources.tool;
043:
044: import java.io.File;
045: import java.util.ArrayList;
046: import java.util.List;
047: import javax.swing.JComponent;
048: import org.netbeans.api.project.Project;
049: import org.netbeans.api.visual.action.ActionFactory;
050: import org.netbeans.api.visual.action.WidgetAction;
051: import org.netbeans.modules.compapp.javaee.sunresources.ResourceAggregator;
052: import org.netbeans.modules.compapp.javaee.sunresources.SunResourcesUtil;
053: import org.netbeans.modules.compapp.javaee.sunresources.actions.WidgetMoveProvider;
054: import org.netbeans.modules.compapp.javaee.sunresources.generated.sunresources13.Resources;
055: import org.netbeans.modules.compapp.javaee.sunresources.tool.archive.ApplicationArchive;
056: import org.netbeans.modules.compapp.javaee.sunresources.tool.archive.Archive;
057: import org.netbeans.modules.compapp.javaee.sunresources.tool.archive.ArchiveConstants;
058: import org.netbeans.modules.compapp.javaee.sunresources.tool.archive.EJBArchive;
059: import org.netbeans.modules.compapp.javaee.sunresources.tool.archive.WebArchive;
060: import org.netbeans.modules.compapp.javaee.sunresources.tool.graph.CMapScene;
061: import org.netbeans.modules.compapp.javaee.sunresources.tool.graph.VisualUtil;
062: import org.netbeans.spi.project.support.ant.AntProjectHelper;
063: import org.netbeans.spi.project.support.ant.EditableProperties;
064: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
065: import org.openide.filesystems.FileObject;
066: import org.openide.util.NbBundle;
067:
068: /**
069: *
070: * @author echou
071: */
072: public class JavaEETool {
073:
074: private ArchiveConstants.ArchiveType type;
075: private Project p;
076: private Archive archive;
077: private CMapScene scene;
078: private boolean valid = true;
079:
080: public JavaEETool(File directory) throws Exception {
081:
082: }
083:
084: public JavaEETool(ArchiveConstants.ArchiveType type, Project p)
085: throws Exception {
086: this .type = type;
087: this .p = p;
088:
089: if (type == ArchiveConstants.ArchiveType.EAR) {
090: archive = new ApplicationArchive(p);
091: } else if (type == ArchiveConstants.ArchiveType.EJB) {
092: archive = new EJBArchive(p);
093: } else if (type == ArchiveConstants.ArchiveType.WAR) {
094: archive = new WebArchive(p);
095: } else {
096: throw new Exception(NbBundle.getMessage(JavaEETool.class,
097: "EXC_unknown_archive", type.toString()));
098: }
099: archive.open();
100: scene = VisualUtil.constructCMapScene(archive);
101:
102: // hover action
103: scene.registerNodeWidgetAction(scene.createWidgetHoverAction());
104:
105: // move action
106: WidgetAction moveAction = ActionFactory.createMoveAction(null,
107: new WidgetMoveProvider(archive.getJAXBHandler()));
108: scene.registerNodeWidgetAction(moveAction);
109: }
110:
111: public void close() throws Exception {
112: archive.close();
113: archive = null;
114: valid = false;
115: }
116:
117: public ResourceAggregator getResourceAggregator() {
118: isValid();
119: return archive.getResourceAggregator();
120: }
121:
122: public FileObject getResourceDir() {
123: isValid();
124: return archive.getResourceDir();
125: }
126:
127: public JComponent getGraphView() {
128: isValid();
129: JComponent sceneView = scene.getView();
130: if (sceneView == null) {
131: sceneView = scene.createView();
132: }
133: return sceneView;
134: }
135:
136: private void isValid() {
137: if (!valid) {
138: throw new IllegalStateException(NbBundle.getMessage(
139: JavaEETool.class, "EXC_already_closed"));
140: }
141: }
142:
143: public static void main(String[] args) {
144: //File ear = new File("C:/nbprojects/EnterpriseApplication1/dist/EnterpriseApplication1.ear");
145: //File ear = new File("C:/nbprojects/EnterpriseApplication14/dist/EnterpriseApplication14.ear");
146: File ear = new File("C:/temp/EnterpriseApplication4.ear");
147: File tmpDir = new File("C:/temp");
148: //File xml = new File("C:/testcode/wasilla/graph3.xml");
149:
150: try {
151: /*
152: File appPath = FileUtil.explode(ear, tmpDir);
153: ApplicationArchive archive = new ApplicationArchive(appPath);
154: archive.open();
155:
156: System.out.println("archive = " + archive);
157: System.out.println("cmap=" + archive.getCMap());
158:
159: CMapScene scene = VisualUtil.constructCMapScene(archive);
160:
161: // hover action
162: scene.registerNodeWidgetAction(scene.createWidgetHoverAction());
163:
164: // move action
165: WidgetAction moveAction =
166: ActionFactory.createMoveAction(null, new WidgetMoveProvider(archive.getJAXBHandler()));
167: scene.registerNodeWidgetAction(moveAction);
168:
169:
170:
171: SceneSupport.show (scene, VisualUtil.MAX_WIDTH, VisualUtil.MAX_HEIGHT,
172: archive, ear);
173: */
174:
175: } catch (Exception e) {
176: e.printStackTrace();
177: }
178:
179: }
180:
181: }
|