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-2006 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.j2ee.sun.ddloaders.multiview.web;
043:
044: import java.io.IOException;
045: import java.util.Map;
046: import org.netbeans.modules.j2ee.dd.api.web.WebAppMetadata;
047: import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
048: import org.netbeans.modules.j2ee.metadata.model.api.MetadataModelException;
049: import org.netbeans.modules.j2ee.sun.dd.api.ASDDVersion;
050: import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
051: import org.netbeans.modules.j2ee.sun.dd.api.web.Servlet;
052: import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
053: import org.netbeans.modules.j2ee.sun.ddloaders.multiview.common.DDBinding;
054: import org.netbeans.modules.j2ee.sun.ddloaders.multiview.common.NamedBeanGroupNode;
055: import org.netbeans.modules.xml.multiview.SectionNode;
056: import org.netbeans.modules.xml.multiview.ui.SectionNodeView;
057: import org.openide.ErrorManager;
058: import org.openide.util.NbBundle;
059:
060: /**
061: * @author Peter Williams
062: */
063: public class ServletGroupNode extends NamedBeanGroupNode {
064:
065: private SunWebApp sunWebApp;
066:
067: public ServletGroupNode(SectionNodeView sectionNodeView,
068: SunWebApp sunWebApp, ASDDVersion version) {
069: super (sectionNodeView, sunWebApp, Servlet.SERVLET_NAME,
070: Servlet.class, NbBundle.getMessage(
071: ServletGroupNode.class,
072: "LBL_ServletGroupHeader"), // NOI18N
073: ICON_BASE_SERVLET_NODE, version);
074:
075: this .sunWebApp = sunWebApp;
076: enableAddAction(NbBundle.getMessage(ServletGroupNode.class,
077: "LBL_AddServlet")); // NOI18N
078: }
079:
080: protected SectionNode createNode(DDBinding binding) {
081: return new ServletNode(getSectionNodeView(), binding, version);
082: }
083:
084: protected CommonDDBean[] getBeansFromModel() {
085: return sunWebApp.getServlet();
086: }
087:
088: protected CommonDDBean addNewBean() {
089: Servlet newServlet = sunWebApp.newServlet();
090: newServlet.setServletName(getNewBeanId(PFX_SERVLET)); // NOI18N
091: return addBean(newServlet);
092: }
093:
094: protected CommonDDBean addBean(CommonDDBean newBean) {
095: sunWebApp.addServlet((Servlet) newBean);
096: return newBean;
097: }
098:
099: protected void removeBean(CommonDDBean bean) {
100: Servlet servlet = (Servlet) bean;
101: sunWebApp.removeServlet(servlet);
102: }
103:
104: // ------------------------------------------------------------------------
105: // DescriptorReader implementation
106: // ------------------------------------------------------------------------
107: @Override
108: public Map<String, Object> readDescriptor() {
109: Map<String, Object> resultMap = null;
110:
111: org.netbeans.modules.j2ee.dd.api.common.RootInterface stdRootDD = getStandardRootDD();
112: if (stdRootDD instanceof org.netbeans.modules.j2ee.dd.api.web.WebApp) {
113: org.netbeans.modules.j2ee.dd.api.web.WebApp webApp = (org.netbeans.modules.j2ee.dd.api.web.WebApp) stdRootDD;
114: resultMap = ServletMetadataReader.readDescriptor(webApp);
115: }
116:
117: return resultMap;
118: }
119:
120: @Override
121: public Map<String, Object> readAnnotations() {
122: Map<String, Object> resultMap = null;
123:
124: try {
125: MetadataModel<WebAppMetadata> webAppModel = getMetadataModel(WebAppMetadata.class);
126: if (webAppModel != null) {
127: resultMap = webAppModel
128: .runReadAction(new ServletMetadataReader());
129: }
130: } catch (MetadataModelException ex) {
131: ErrorManager.getDefault().notify(
132: ErrorManager.INFORMATIONAL, ex);
133: } catch (IOException ex) {
134: ErrorManager.getDefault().notify(
135: ErrorManager.INFORMATIONAL, ex);
136: }
137:
138: return resultMap;
139: }
140:
141: // ------------------------------------------------------------------------
142: // BeanResolver interface implementation
143: // ------------------------------------------------------------------------
144: public CommonDDBean createBean() {
145: return sunWebApp.newServlet();
146: }
147:
148: public String getBeanName(CommonDDBean sunBean) {
149: return ((Servlet) sunBean).getServletName();
150: }
151:
152: public void setBeanName(CommonDDBean sunBean, String newName) {
153: ((Servlet) sunBean).setServletName(newName);
154: }
155:
156: public String getSunBeanNameProperty() {
157: return Servlet.SERVLET_NAME;
158: }
159:
160: public String getBeanName(
161: org.netbeans.modules.j2ee.dd.api.common.CommonDDBean standardBean) {
162: return ((org.netbeans.modules.j2ee.dd.api.web.Servlet) standardBean)
163: .getServletName();
164: }
165:
166: public String getStandardBeanNameProperty() {
167: return STANDARD_SERVLET_NAME;
168: }
169:
170: }
|