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.compapp.casaeditor.properties.spi;
042:
043: import java.lang.reflect.InvocationTargetException;
044: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaComponent;
045: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaExtensibilityElement;
046: import org.netbeans.modules.compapp.casaeditor.nodes.CasaNode;
047:
048: /**
049: * <code>Node.Property</code> for CASA configuration extension.
050: *
051: * @author jqian
052: */
053: public class ExtensionProperty<T> extends BaseCasaProperty<T> {
054:
055: /**
056: * A CASA extension point element, that is, a non-extensibility element
057: * that is the parent of extensibility elements,
058: * e.x., casa:connection
059: */
060: protected CasaComponent extensionPointComponent;
061: /**
062: * The top-level extensiblity elements under a CASA extension point element,
063: * e.x., redelivery:redelivery
064: */
065: protected CasaExtensibilityElement firstEE;
066:
067: public ExtensionProperty(CasaNode node,
068: CasaComponent extensionPointComponent,
069: CasaExtensibilityElement firstEE,
070: CasaExtensibilityElement lastEE, String propertyType,
071: Class<T> valueType, String propertyName,
072: String displayName, String description) {
073: super (node, lastEE, propertyType, valueType, propertyName,
074: displayName, description);
075:
076: this .extensionPointComponent = extensionPointComponent;
077: this .firstEE = firstEE;
078: }
079:
080: @SuppressWarnings("unchecked")
081: public T getValue() throws IllegalAccessException,
082: InvocationTargetException {
083: return (T) getStringValue();
084: }
085:
086: protected String getStringValue() {
087: CasaExtensibilityElement casaEE = (CasaExtensibilityElement) getComponent();
088: return casaEE.getAttribute(getName());
089: }
090:
091: public void setValue(T value) throws IllegalAccessException,
092: IllegalArgumentException, InvocationTargetException {
093: CasaExtensibilityElement lastEE = (CasaExtensibilityElement) getComponent();
094: if (firstEE.getParent() == null) {
095: // The extensibility element does not exist in the CASA model yet.
096:
097: // 1. Set the attribute value out of a transaction context.
098: lastEE.setAttribute(getName(), value.toString());
099:
100: // 2. Add the first extensibility element with the new attribute
101: // value into the CASA model.
102: getModel().addExtensibilityElement(extensionPointComponent,
103: firstEE);
104: } else {
105: getModel().setExtensibilityElementAttribute(lastEE,
106: getName(), value.toString());
107: }
108: }
109: }
|