Skip to main content
summaryrefslogtreecommitdiffstats
blob: f524a4858c6b6274b25d673d65d90fa2d3c985ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*******************************************************************************
 * Copyright (c) 2007, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20071024   196997 pmoogk@ca.ibm.com - Peter Moogk
 * 20071024   196997 pmoogk@ca.ibm.com - Peter Moogk
 * 20080428   227501 pmoogk@ca.ibm.com - Peter Moogk, Fixed toLowerCase Locale problem.
 *******************************************************************************/
package org.eclipse.wst.ws.service.policy.utils;

import java.util.Locale;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.wst.ws.service.internal.policy.DescriptorImpl;
import org.eclipse.wst.ws.service.policy.ServicePolicyActivator;

public class RegistryUtils
{
  public static DescriptorImpl loadDescriptor( IConfigurationElement element )
  {
    DescriptorImpl descriptor = new DescriptorImpl();
    
    String shortName   = getAttribute( element, "shortname" ); //$NON-NLS-1$
    String longName    = getAttribute( element, "longname" ); //$NON-NLS-1$
    String description = getAttribute( element, "description" ); //$NON-NLS-1$
    String iconPath    = getAttribute( element, "iconpath" ); //$NON-NLS-1$
    String contextHelp = getAttribute( element, "contexthelpid" ); //$NON-NLS-1$
    
    if( shortName == null && longName == null )
    {
      ServicePolicyActivator.logError( "Short name or Long name missing from service policy descriptor.", null ); //$NON-NLS-1$
    }
    else if( shortName == null )
    {
      shortName = longName;
    }
    else if( longName == null )
    {
      longName = shortName;
    }
    
    descriptor.setDescription( description );
    descriptor.setShortName( shortName );
    descriptor.setLongName( longName );
    descriptor.setContextHelpId( contextHelp );
    
    if( iconPath != null )
    {
      descriptor.setIconPath( iconPath );
      descriptor.setIconBundleId( element.getContributor().getName() );
    }
    
    descriptor.resetHasChanged();
    return descriptor;
  }
  
  /**
   * This method takes in a lower case attribute name.  It will then return
   * the same attribute name that includes potentially uppercase characters.
   * This method allows clients to specify attribute names in a case insensitive
   * fashion.
   *  
   * @param element
   * @param attribute
   * @return
   */
  public static String getAttributeName( IConfigurationElement element, String attribute )
  {
    String[] names  = element.getAttributeNames();
    String   result = null;
    
    for( String name : names )
    {
      if( name.toLowerCase( Locale.ENGLISH ).equals( attribute ) )
      {
        result = name;
        break;
      }
    }
        
    return result;
  }
  
  public static String getAttribute( IConfigurationElement element, String attribute )
  {
    String[] names = element.getAttributeNames();
    String   value = null;
    
    for( String name : names )
    {
      if( name.toLowerCase( Locale.ENGLISH ).equals( attribute ) )
      {
        value = element.getAttribute( name );
        break;
      }
    }
        
    return value;
  }
}

Back to the top