001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.xslt.mapper.model.nodes.actions;
021:
022: import java.awt.Image;
023: import java.util.HashMap;
024: import java.util.Map;
025: import org.netbeans.modules.xslt.model.CopyOf;
026: import org.netbeans.modules.xslt.model.ForEach;
027: import org.netbeans.modules.xslt.model.If;
028: import org.netbeans.modules.xslt.model.Instruction;
029: import org.openide.util.NbBundle;
030: import org.openide.util.Utilities;
031:
032: /**
033: *
034: * @author nk160297
035: */
036: public enum SupportedRuleTypes {
037: IF(If.class), FOR_EACH(ForEach.class), COPY_OF(CopyOf.class);
038:
039: private static Map<Class<? extends Instruction>, SupportedRuleTypes> classToType;
040:
041: private static final String COMMON_RULE_IMAGE_NAME = "org/netbeans/modules/xslt/mapper/model/nodes/actions/Instruction.png"; // NOI18N
042: private static final Image COMMON_IMAGE = Utilities
043: .loadImage(COMMON_RULE_IMAGE_NAME);
044:
045: private Class<? extends Instruction> myInterface = null;
046: private String myDisplayName;
047: private Image myDefaultImage;
048:
049: SupportedRuleTypes() {
050: }
051:
052: SupportedRuleTypes(Class<? extends Instruction> instrInterf) {
053: assert instrInterf.isInterface() : "The interface should be specified"; // NOI8N
054: myInterface = instrInterf;
055: //
056: registerType(instrInterf, this );
057: }
058:
059: public Class<? extends Instruction> getInterface() {
060: return myInterface;
061: }
062:
063: private static synchronized void registerType(
064: Class<? extends Instruction> instrInterf,
065: SupportedRuleTypes ruleType) {
066: if (instrInterf != null && ruleType != null) {
067: if (classToType == null) {
068: classToType = new HashMap<Class<? extends Instruction>, SupportedRuleTypes>();
069: }
070: classToType.put(instrInterf, ruleType);
071: }
072: }
073:
074: public static SupportedRuleTypes getRuleType(Instruction instruction) {
075: return classToType.get(instruction.getClass());
076: }
077:
078: public static SupportedRuleTypes getRuleType(
079: Class<? extends Instruction> instrClass) {
080: return classToType.get(instrClass);
081: }
082:
083: public static Image getCommonImage() {
084: return COMMON_IMAGE;
085: }
086:
087: public synchronized String getDisplayName() {
088: if (myDisplayName == null) {
089: try {
090: myDisplayName = NbBundle.getMessage(
091: SupportedRuleTypes.class, this .toString());
092: } catch (Exception ex) {
093: myDisplayName = name();
094: }
095: }
096: return myDisplayName;
097: }
098:
099: public synchronized Image getImage() {
100: return COMMON_IMAGE;
101: }
102:
103: }
|