KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > advice > SecurityActions


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.aop.advice;
23
24 import java.beans.PropertyEditorManager JavaDoc;
25 import java.security.AccessController JavaDoc;
26 import java.security.PrivilegedActionException JavaDoc;
27 import java.security.PrivilegedExceptionAction JavaDoc;
28
29 import org.jboss.util.propertyeditor.ClassArrayEditor;
30 import org.jboss.util.propertyeditor.IntArrayEditor;
31 import org.jboss.util.propertyeditor.StringArrayEditor;
32
33 import javassist.CtClass;
34
35 /**
36  *
37  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
38  * @version $Revision: 45976 $
39  */

40 public class SecurityActions
41 {
42    private interface InitPropertyEditorsAction
43    {
44       void initEditors();
45       
46       InitPropertyEditorsAction PRIVILEGED = new InitPropertyEditorsAction()
47       {
48          public void initEditors()
49          {
50             try
51             {
52                AccessController.doPrivileged(new PrivilegedExceptionAction JavaDoc()
53                {
54                   public Object JavaDoc run() throws Exception JavaDoc
55                   {
56                      doInitEditors();
57                      return null;
58                   }
59                });
60             }
61             catch (PrivilegedActionException JavaDoc e)
62             {
63                throw new RuntimeException JavaDoc(e.getException());
64             }
65          }
66       };
67
68       InitPropertyEditorsAction NON_PRIVILEGED = new InitPropertyEditorsAction()
69       {
70          public void initEditors()
71          {
72             doInitEditors();
73          }
74       };
75    }
76
77    private static void doInitEditors()
78    {
79       String JavaDoc[] currentPath = PropertyEditorManager.getEditorSearchPath();
80       int length = currentPath != null ? currentPath.length : 0;
81       String JavaDoc[] newPath = new String JavaDoc[length+2];
82       System.arraycopy(currentPath, 0, newPath, 2, length);
83       // Put the JBoss editor path first
84
// The default editors are not very flexible
85
newPath[0] = "org.jboss.util.propertyeditor";
86       newPath[1] = "org.jboss.mx.util.propertyeditor";
87       PropertyEditorManager.setEditorSearchPath(newPath);
88
89       /* Register the editor types that will not be found using the standard
90       class name to editor name algorithm. For example, the type String[] has
91       a name '[Ljava.lang.String;' which does not map to a XXXEditor name.
92       */

93       Class JavaDoc strArrayType = String JavaDoc[].class;
94       PropertyEditorManager.registerEditor(strArrayType, StringArrayEditor.class);
95       Class JavaDoc clsArrayType = Class JavaDoc[].class;
96       PropertyEditorManager.registerEditor(clsArrayType, ClassArrayEditor.class);
97       Class JavaDoc intArrayType = int[].class;
98       PropertyEditorManager.registerEditor(intArrayType, IntArrayEditor.class);
99    }
100
101
102    static void initEditors()
103    {
104       if (System.getSecurityManager() == null)
105       {
106          InitPropertyEditorsAction.NON_PRIVILEGED.initEditors();
107       }
108       else
109       {
110          InitPropertyEditorsAction.PRIVILEGED.initEditors();
111       }
112    }
113    
114 }
115
Popular Tags