Source Code Cross Referenced for NamePattern.java in  » Net » Terracotta » com » tc » aspectwerkz » expression » regexp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » com.tc.aspectwerkz.expression.regexp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tc.aspectwerkz.expression.regexp;
005:
006:        import com.tc.aspectwerkz.util.Strings;
007:        import com.tc.aspectwerkz.expression.ExpressionException;
008:
009:        import java.io.ObjectInputStream;
010:
011:        /**
012:         * Implements the regular expression pattern matcher for names.
013:         *
014:         * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
015:         */
016:        public class NamePattern extends Pattern {
017:            /**
018:             * The name pattern.
019:             */
020:            protected transient com.tc.jrexx.regex.Pattern m_namePattern;
021:
022:            /**
023:             * The name pattern as a string.
024:             */
025:            protected String m_pattern;
026:
027:            /**
028:             * Private constructor.
029:             *
030:             * @param pattern the pattern
031:             */
032:            NamePattern(final String pattern) {
033:                m_pattern = pattern;
034:                escape(m_pattern);
035:            }
036:
037:            /**
038:             * Matches a name.
039:             *
040:             * @param name the name
041:             * @return true if we have a matche
042:             */
043:            public boolean matches(final String name) {
044:                if (name == null) {
045:                    throw new IllegalArgumentException("name can not be null");
046:                }
047:                if (name.equals("")) {
048:                    return false;
049:                }
050:                return m_namePattern.contains(name);
051:            }
052:
053:            /**
054:             * Returns the pattern as a string.
055:             *
056:             * @return the pattern
057:             */
058:            public String getPattern() {
059:                return m_pattern;
060:            }
061:
062:            /**
063:             * Escapes the name pattern.
064:             *
065:             * @param namePattern the name pattern
066:             */
067:            protected void escape(String namePattern) {
068:                try {
069:                    if (namePattern.equals(REGULAR_WILDCARD)) {
070:                        namePattern = "[a-zA-Z0-9_$.]+";
071:                    } else {
072:                        namePattern = Strings.replaceSubString(namePattern,
073:                                "*", "[a-zA-Z0-9_$]*");
074:                    }
075:                    m_namePattern = new com.tc.jrexx.regex.Pattern(namePattern);
076:                } catch (Throwable e) {
077:                    throw new ExpressionException(
078:                            "type pattern is not well formed: " + namePattern,
079:                            e);
080:                }
081:            }
082:
083:            /**
084:             * Provides custom deserialization.
085:             *
086:             * @param stream the object input stream containing the serialized object
087:             * @throws Exception in case of failure
088:             */
089:            private void readObject(final ObjectInputStream stream)
090:                    throws Exception {
091:                ObjectInputStream.GetField fields = stream.readFields();
092:                m_pattern = (String) fields.get("m_pattern", null);
093:                escape(m_pattern);
094:            }
095:
096:            public int hashCode() {
097:                int result = 17;
098:                result = (37 * result) + hashCodeOrZeroIfNull(m_pattern);
099:                result = (37 * result) + hashCodeOrZeroIfNull(m_namePattern);
100:                return result;
101:            }
102:
103:            protected static int hashCodeOrZeroIfNull(final Object o) {
104:                if (null == o) {
105:                    return 19;
106:                }
107:                return o.hashCode();
108:            }
109:
110:            public boolean equals(final Object o) {
111:                if (this  == o) {
112:                    return true;
113:                }
114:                if (!(o instanceof  NamePattern)) {
115:                    return false;
116:                }
117:                final NamePattern obj = (NamePattern) o;
118:                return areEqualsOrBothNull(obj.m_pattern, this .m_pattern)
119:                        && areEqualsOrBothNull(obj.m_namePattern,
120:                                this .m_namePattern);
121:            }
122:
123:            protected static boolean areEqualsOrBothNull(final Object o1,
124:                    final Object o2) {
125:                if (null == o1) {
126:                    return (null == o2);
127:                }
128:                return o1.equals(o2);
129:            }
130:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.