[webbeans-commits] Webbeans SVN: r2037 - in extensions/trunk/logging/src: test and 7 other directories.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2009-03-16 08:24:23 -0400 (Mon, 16 Mar 2009)
New Revision: 2037
Added:
extensions/trunk/logging/src/test/
extensions/trunk/logging/src/test/java/
extensions/trunk/logging/src/test/java/org/
extensions/trunk/logging/src/test/java/org/jboss/
extensions/trunk/logging/src/test/java/org/jboss/webbeans/
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/LoggingTest.java
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
extensions/trunk/logging/src/test/resources/
extensions/trunk/logging/src/test/resources/log4j.xml
Log:
Added some unit tests for logging.
Added: extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/LoggingTest.java
===================================================================
--- extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/LoggingTest.java (rev 0)
+++ extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/LoggingTest.java 2009-03-16 12:24:23 UTC (rev 2037)
@@ -0,0 +1,59 @@
+package org.jboss.webbeans.test.log;
+
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+import org.testng.annotations.Test;
+
+/**
+ * Simple tests to verify proper operation of the logging system.
+ *
+ * @author David Allen
+ *
+ */
+public class LoggingTest
+{
+ private static final String TEST_MSG = "Test Message";
+
+ @Test
+ public void testLogProvider()
+ {
+ LogProvider logProvider = Logging.getLogProvider(LoggingTest.class);
+ assert logProvider != null;
+ }
+
+ @Test
+ public void testLogBasedOnClassObject()
+ {
+ Log log = Logging.getLog(LoggingTest.class);
+ assert log != null : "No Log object returned";
+
+ log.info(TEST_MSG);
+ assert TestAppender.getLastEvent() != null : "There was no last event in Log4j";
+ assert TestAppender.getLastEvent().getLoggerName().equals("org.jboss.webbeans.test.log.LoggingTest");
+ assert TestAppender.getLastEvent().getRenderedMessage().equals(TEST_MSG) : "Last event has incorrect message";
+ }
+
+ @Test
+ public void testLogBasedOnStringObject()
+ {
+ Log log = Logging.getLog("MyLogger");
+ assert log != null;
+
+ log.info(TEST_MSG);
+ assert TestAppender.getLastEvent() != null : "There was no last event in Log4j";
+ assert TestAppender.getLastEvent().getLoggerName().equals("MyLogger");
+ assert TestAppender.getLastEvent().getRenderedMessage().equals(TEST_MSG) : "Last event has incorrect message";
+ }
+
+ @Test
+ public void testLogMessageFormatting()
+ {
+ Log log = Logging.getLog(LoggingTest.class);
+ assert log != null : "No Log object returned";
+
+ log.info("Message with {0} parameters starting with {1} and including {2}", 3, "param1", "param2");
+ assert TestAppender.getLastEvent() != null : "There was no last event in Log4j";
+ assert TestAppender.getLastEvent().getRenderedMessage().equals("Message with 3 parameters starting with param1 and including param2");
+ }
+}
Property changes on: extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/LoggingTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
===================================================================
--- extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/TestAppender.java (rev 0)
+++ extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/TestAppender.java 2009-03-16 12:24:23 UTC (rev 2037)
@@ -0,0 +1,21 @@
+package org.jboss.webbeans.test.log;
+
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.varia.NullAppender;
+
+public class TestAppender extends NullAppender
+{
+ private static LoggingEvent lastEvent;
+
+ @Override
+ public void doAppend(LoggingEvent event)
+ {
+ lastEvent = event;
+ }
+
+ public static LoggingEvent getLastEvent()
+ {
+ return lastEvent;
+ }
+
+}
Property changes on: extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: extensions/trunk/logging/src/test/resources/log4j.xml
===================================================================
--- extensions/trunk/logging/src/test/resources/log4j.xml (rev 0)
+++ extensions/trunk/logging/src/test/resources/log4j.xml 2009-03-16 12:24:23 UTC (rev 2037)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+ <appender name="CONSOLE" class="org.jboss.webbeans.test.log.TestAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{2}] %m%n"/>
+ </layout>
+ </appender>
+
+ <category name="org.jboss.webbeans.test">
+ <priority value="INFO"/>
+ </category>
+
+ <root>
+ <priority value="INFO"/>
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</log4j:configuration>
Property changes on: extensions/trunk/logging/src/test/resources/log4j.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2036 - extensions/trunk/logging.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-16 08:09:56 -0400 (Mon, 16 Mar 2009)
New Revision: 2036
Modified:
extensions/trunk/logging/
Log:
ignores
Property changes on: extensions/trunk/logging
___________________________________________________________________
Name: svn:ignore
- .project
.classpath
target
+ .project
.classpath
target
.settings
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2035 - ri/trunk/jboss-tck-runner/src/test/resources.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2009-03-16 08:09:05 -0400 (Mon, 16 Mar 2009)
New Revision: 2035
Added:
ri/trunk/jboss-tck-runner/src/test/resources/log4j.xml
Log:
Added log4j.xml file to specify filter for TCK test log messages.
Added: ri/trunk/jboss-tck-runner/src/test/resources/log4j.xml
===================================================================
--- ri/trunk/jboss-tck-runner/src/test/resources/log4j.xml (rev 0)
+++ ri/trunk/jboss-tck-runner/src/test/resources/log4j.xml 2009-03-16 12:09:05 UTC (rev 2035)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{2}] %m%n"/>
+ </layout>
+ <filter class="org.apache.log4j.varia.StringMatchFilter">
+ <param name="AcceptOnMatch" value="false" />
+ <param name="StringToMatch" value="Failure while notifying an observer of event [a]" />
+ </filter>
+ </appender>
+
+ <!-- ############### Embedded EJB3 ################# -->
+ <category name="org.jboss">
+ <priority value="ERROR"/>
+ </category>
+
+ <category name="org.jboss.test">
+ <priority value="ERROR"/>
+ </category>
+
+ <category name="com.arjuna">
+ <priority value="ERROR"/>
+ </category>
+
+ <!-- ############### Hibernate logging ################# -->
+
+ <category name="org.hibernate">
+ <priority value="ERROR"/>
+ </category>
+
+ <!--
+ <category name="org.hibernate.SQL">
+ <priority value="TRACE"/>
+ </category>
+
+ <category name="org.hibernate.type">
+ <priority value="TRACE"/>
+ </category>
+
+ <category name="org.hibernate.loader">
+ <priority value="TRACE"/>
+ </category>
+ <category name="org.hibernate.cache">
+ <priority value="TRACE"/>
+ </category>
+ -->
+
+ <!-- ############### Web Beans logging ################### -->
+
+ <category name="org.jboss.webbeans">
+ <priority value="WARN"/>
+ </category>
+
+ <category name="org.jboss.webbeans.tck">
+ <priority value="INFO"/>
+ </category>
+
+ <category name="org.jboss.testharness">
+ <priority value="INFO"/>
+ </category>
+
+ <root>
+ <priority value="INFO"/>
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</log4j:configuration>
Property changes on: ri/trunk/jboss-tck-runner/src/test/resources/log4j.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2033 - test-harness/trunk/jboss/src/main/resources.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-16 08:03:20 -0400 (Mon, 16 Mar 2009)
New Revision: 2033
Modified:
test-harness/trunk/jboss/src/main/resources/log4j.xml
Log:
clean up
Modified: test-harness/trunk/jboss/src/main/resources/log4j.xml
===================================================================
--- test-harness/trunk/jboss/src/main/resources/log4j.xml 2009-03-16 10:58:56 UTC (rev 2032)
+++ test-harness/trunk/jboss/src/main/resources/log4j.xml 2009-03-16 12:03:20 UTC (rev 2033)
@@ -8,13 +8,9 @@
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{2}] %m%n"/>
</layout>
- <filter class="org.apache.log4j.varia.StringMatchFilter">
- <param name="AcceptOnMatch" value="false" />
- <param name="StringToMatch" value="Failure while notifying an observer of event [a]" />
- </filter>
</appender>
- <!-- ############### Embedded EJB3 ################# -->
+ <!-- ############### JBoss ################# -->
<category name="org.jboss">
<priority value="ERROR"/>
</category>
@@ -49,17 +45,7 @@
<priority value="TRACE"/>
</category>
-->
-
- <!-- ############### Web Beans logging ################### -->
-
- <category name="org.jboss.webbeans">
- <priority value="WARN"/>
- </category>
- <category name="org.jboss.webbeans.tck">
- <priority value="INFO"/>
- </category>
-
<category name="org.jboss.testharness">
<priority value="INFO"/>
</category>
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2032 - in extensions/trunk/logging: .settings and 5 other directories.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2009-03-16 06:58:56 -0400 (Mon, 16 Mar 2009)
New Revision: 2032
Added:
extensions/trunk/logging/.settings/
extensions/trunk/logging/.settings/org.maven.ide.eclipse.prefs
extensions/trunk/logging/src/main/java/org/
extensions/trunk/logging/src/main/java/org/jboss/
extensions/trunk/logging/src/main/java/org/jboss/webbeans/
extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/
extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/JDKProvider.java
extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Log.java
extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Log4JProvider.java
extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/LogImpl.java
extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/LogProvider.java
extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Logging.java
Modified:
extensions/trunk/logging/
Log:
New logging project to be used by Web Beans and Seam projects
Property changes on: extensions/trunk/logging
___________________________________________________________________
Name: svn:ignore
+ .project
.classpath
target
Added: extensions/trunk/logging/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- extensions/trunk/logging/.settings/org.maven.ide.eclipse.prefs (rev 0)
+++ extensions/trunk/logging/.settings/org.maven.ide.eclipse.prefs 2009-03-16 10:58:56 UTC (rev 2032)
@@ -0,0 +1,8 @@
+#Mon Mar 16 11:30:27 CET 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+version=1
Property changes on: extensions/trunk/logging/.settings/org.maven.ide.eclipse.prefs
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/JDKProvider.java
===================================================================
--- extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/JDKProvider.java (rev 0)
+++ extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/JDKProvider.java 2009-03-16 10:58:56 UTC (rev 2032)
@@ -0,0 +1,156 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.log;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Gavin King
+ *
+ */
+class JDKProvider implements LogProvider
+{
+ private final Logger logger;
+ private final boolean isWrapped;
+
+ JDKProvider(String category, boolean wrapped)
+ {
+ this.logger = Logger.getLogger(category);
+ this.isWrapped = wrapped;
+ }
+
+ private void log(Level level, Object object, Throwable ex)
+ {
+
+ if (logger.isLoggable(level))
+ {
+ Throwable dummyException = new Throwable();
+ StackTraceElement locations[] = dummyException.getStackTrace();
+ String className = "unknown";
+ String methodName = "unknown";
+ int depth = isWrapped ? 3 : 2;
+ if (locations != null && locations.length > depth)
+ {
+ StackTraceElement caller = locations[depth];
+ className = caller.getClassName();
+ methodName = caller.getMethodName();
+ }
+ if (ex == null)
+ {
+ logger.logp(level, className, methodName, String.valueOf(object));
+ }
+ else
+ {
+ logger.logp(level, className, methodName, String.valueOf(object), ex);
+ }
+ }
+
+ }
+
+ public void debug(Object object, Throwable t)
+ {
+ log(Level.FINE, object, t);
+ }
+
+ public void debug(Object object)
+ {
+ log(Level.FINE, object, null);
+ }
+
+ public void error(Object object, Throwable t)
+ {
+ log(Level.SEVERE, object, t);
+ }
+
+ public void error(Object object)
+ {
+ log(Level.SEVERE, object, null);
+ }
+
+ public void fatal(Object object, Throwable t)
+ {
+ log(Level.SEVERE, object, t);
+ }
+
+ public void fatal(Object object)
+ {
+ log(Level.SEVERE, object, null);
+ }
+
+ public void info(Object object, Throwable t)
+ {
+ log(Level.INFO, object, t);
+ }
+
+ public void info(Object object)
+ {
+ log(Level.INFO, object, null);
+ }
+
+ public boolean isDebugEnabled()
+ {
+ return logger.isLoggable(Level.FINE);
+ }
+
+ public boolean isErrorEnabled()
+ {
+ return logger.isLoggable(Level.SEVERE);
+ }
+
+ public boolean isFatalEnabled()
+ {
+ return logger.isLoggable(Level.SEVERE);
+ }
+
+ public boolean isInfoEnabled()
+ {
+ return logger.isLoggable(Level.INFO);
+ }
+
+ public boolean isTraceEnabled()
+ {
+ return logger.isLoggable(Level.FINER);
+ }
+
+ public boolean isWarnEnabled()
+ {
+ return logger.isLoggable(Level.WARNING);
+ }
+
+ public void trace(Object object, Throwable t)
+ {
+ log(Level.FINER, object, t);
+ }
+
+ public void trace(Object object)
+ {
+ log(Level.FINER, object, null);
+ }
+
+ public void warn(Object object, Throwable t)
+ {
+ log(Level.WARNING, object, t);
+ }
+
+ public void warn(Object object)
+ {
+ log(Level.WARNING, object, null);
+ }
+
+}
Property changes on: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/JDKProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Log.java
===================================================================
--- extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Log.java (rev 0)
+++ extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Log.java 2009-03-16 10:58:56 UTC (rev 2032)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.log;
+
+/**
+ * <p>A <code>Log</code> object is used by RI classes to log messages.
+ * They will be logged in any environment that has setup a logging service
+ * such as Log4J or the standard JDK logging facilities. In fact, this
+ * logging interface is very similar to the other facilities with the
+ * difference that logging methods also take any number of optional
+ * parameters beyond the message object for later interpolation
+ * into the message.</p>
+ *
+ * <p>The idea of using interpolation parameters is very important for
+ * performance reasons in production code. Normally developers write
+ * logging messages similar to this one:
+ * <pre>
+ * log.debug("Started processing of " + obj1 + " with action " + obj2);
+ * </pre>
+ * The problem that arises at runtime in production systems, is that DEBUG
+ * level logging may not be enabled. And even if this logging is going to
+ * be a no-op call, Java must still build the string dynamically that is the
+ * argument to the call. It is the building of this string that can be quite
+ * time consuming. The more complex the objects being concatenated are, the
+ * worse the time penalty incurred is. And this time is completely wasted
+ * since the string may never be used.</p>
+ *
+ * <p>Normally to combat the problem of making this call and building the
+ * string dynamically, the developer uses a conditional statement to invoke
+ * the call only if the corresponding logging level is enabled. So the above
+ * call may end up looking like:
+ * <pre>
+ * if (log.isDebugEnabled())
+ * {
+ * log.debug("Started processing of " + obj1 + " with action " + obj2);
+ * }
+ * </pre>
+ * Ideally, this structure should always be used to avoid the cost of building the
+ * dynamic string (concatenation) and making the unnecessary call. The only
+ * drawback to this is that code can become less readable. In some cases, there
+ * might be more code devoted to logging than the actual behavior required by a
+ * method.</p>
+ *
+ * <p>A cleaner way to do the logging is to use this interface where simple
+ * objects without any concatenation are passed as arguments. Albeit the call
+ * itself may still be a no-op when the logging level is not enabled, this is
+ * still much smaller than the concatenation process with dynamic strings. Each
+ * of the methods defined here will first check to see if the logging level is enabled,
+ * if that feature exists in the underlying logging system. If and only if that logging
+ * level is enabled, will the implementation proceed with concatenation of the strings
+ * and objects passed. So the above code using this interface becomes:
+ * <pre>
+ * log.debug("Started processing of {0} with action {1}, obj1, obj2);
+ * </pre>
+ * </p>
+ *
+ * <p>The interpolation of parameters into the message string are done using
+ * {@link java.text.MessageFormat}. See the documentation on that class for
+ * more ideas of interpolation possibilities. In the above code, <code>obj1</code>
+ * and <code>obj2</code> simply have their <code>toString()</code> methods invoked
+ * to produce a string which is then concatenated.</p>
+ *
+ * @author Gavin King
+ * @author David Allen
+ *
+ */
+public interface Log
+{
+ public boolean isDebugEnabled();
+ public boolean isErrorEnabled();
+ public boolean isFatalEnabled();
+ public boolean isInfoEnabled();
+ public boolean isTraceEnabled();
+ public boolean isWarnEnabled();
+ public void trace(Object object, Object... params);
+ public void trace(Object object, Throwable t, Object... params);
+ public void debug(Object object, Object... params);
+ public void debug(Object object, Throwable t, Object... params);
+ public void info(Object object, Object... params);
+ public void info(Object object, Throwable t, Object... params);
+ public void warn(Object object, Object... params);
+ public void warn(Object object, Throwable t, Object... params);
+ public void error(Object object, Object... params);
+ public void error(Object object, Throwable t, Object... params);
+ public void fatal(Object object, Object... params);
+ public void fatal(Object object, Throwable t, Object... params);
+
+}
\ No newline at end of file
Property changes on: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Log.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Log4JProvider.java
===================================================================
--- extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Log4JProvider.java (rev 0)
+++ extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Log4JProvider.java 2009-03-16 10:58:56 UTC (rev 2032)
@@ -0,0 +1,151 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.log;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * @author Gavin King
+ *
+ */
+final class Log4JProvider implements LogProvider
+{
+ private final Logger logger;
+ private final boolean isWrapped;
+
+ private static final String LOG_IMPL_FQCN = LogImpl.class.getName();
+ private static final String LOG_PROVIDER_FQCN = Log4JProvider.class.getName();
+
+ private static final Level TRACE;
+ static
+ {
+ Object trace;
+ try
+ {
+ trace = Level.class.getDeclaredField("TRACE").get(null);
+ }
+ catch (Exception e)
+ {
+ trace = Level.DEBUG;
+ }
+ TRACE = (Level) trace;
+ }
+
+ Log4JProvider(String category, boolean wrapped)
+ {
+ logger = Logger.getLogger(category);
+ isWrapped = wrapped;
+ }
+
+ private String getFQCN()
+ {
+ return isWrapped ? LOG_IMPL_FQCN : LOG_PROVIDER_FQCN;
+ }
+
+ public void debug(Object object)
+ {
+ logger.log(getFQCN(), Level.DEBUG, object, null);
+ }
+
+ public void debug(Object object, Throwable t)
+ {
+ logger.log(getFQCN(), Level.DEBUG, object, t);
+ }
+
+ public void error(Object object)
+ {
+ logger.log(getFQCN(), Level.ERROR, object, null);
+ }
+
+ public void error(Object object, Throwable t)
+ {
+ logger.log(getFQCN(), Level.ERROR, object, t);
+ }
+
+ public void fatal(Object object)
+ {
+ logger.log(getFQCN(), Level.FATAL, object, null);
+ }
+
+ public void fatal(Object object, Throwable t)
+ {
+ logger.log(getFQCN(), Level.FATAL, object, t);
+ }
+
+ public void info(Object object)
+ {
+ logger.log(getFQCN(), Level.INFO, object, null);
+ }
+
+ public void info(Object object, Throwable t)
+ {
+ logger.log(getFQCN(), Level.INFO, object, t);
+ }
+
+ public boolean isDebugEnabled()
+ {
+ return logger.isEnabledFor(Level.DEBUG);
+ }
+
+ public boolean isErrorEnabled()
+ {
+ return logger.isEnabledFor(Level.ERROR);
+ }
+
+ public boolean isFatalEnabled()
+ {
+ return logger.isEnabledFor(Level.FATAL);
+ }
+
+ public boolean isInfoEnabled()
+ {
+ return logger.isEnabledFor(Level.INFO);
+ }
+
+ public boolean isTraceEnabled()
+ {
+ return logger.isEnabledFor(TRACE);
+ }
+
+ public boolean isWarnEnabled()
+ {
+ return logger.isEnabledFor(Level.WARN);
+ }
+
+ public void trace(Object object)
+ {
+ logger.log(getFQCN(), TRACE, object, null);
+ }
+
+ public void trace(Object object, Throwable t)
+ {
+ logger.log(getFQCN(), TRACE, object, t);
+ }
+
+ public void warn(Object object)
+ {
+ logger.log(getFQCN(), Level.WARN, object, null);
+ }
+
+ public void warn(Object object, Throwable t)
+ {
+ logger.log(getFQCN(), Level.WARN, object, t);
+ }
+
+}
Property changes on: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Log4JProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/LogImpl.java
===================================================================
--- extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/LogImpl.java (rev 0)
+++ extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/LogImpl.java 2009-03-16 10:58:56 UTC (rev 2032)
@@ -0,0 +1,192 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.log;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.text.MessageFormat;
+
+/**
+ *
+ * @author Gavin King
+ *
+ */
+class LogImpl implements Log, Externalizable
+{
+ private transient LogProvider log;
+ private String category;
+
+ public LogImpl()
+ {
+ }
+
+ LogImpl(String category)
+ {
+ this.category = category;
+ this.log = Logging.getLogProvider(category, true);
+ }
+
+ public boolean isDebugEnabled()
+ {
+ return log.isDebugEnabled();
+ }
+
+ public boolean isErrorEnabled()
+ {
+ return log.isErrorEnabled();
+ }
+
+ public boolean isFatalEnabled()
+ {
+ return log.isFatalEnabled();
+ }
+
+ public boolean isInfoEnabled()
+ {
+ return log.isInfoEnabled();
+ }
+
+ public boolean isTraceEnabled()
+ {
+ return log.isTraceEnabled();
+ }
+
+ public boolean isWarnEnabled()
+ {
+ return log.isWarnEnabled();
+ }
+
+ public void trace(Object object, Object... params)
+ {
+ if (isTraceEnabled())
+ {
+ log.trace(interpolate(object, params));
+ }
+ }
+
+ public void trace(Object object, Throwable t, Object... params)
+ {
+ if (isTraceEnabled())
+ {
+ log.trace(interpolate(object, params), t);
+ }
+ }
+
+ public void debug(Object object, Object... params)
+ {
+ if (isDebugEnabled())
+ {
+ log.debug(interpolate(object, params));
+ }
+ }
+
+ public void debug(Object object, Throwable t, Object... params)
+ {
+ if (isDebugEnabled())
+ {
+ log.debug(interpolate(object, params), t);
+ }
+ }
+
+ public void info(Object object, Object... params)
+ {
+ if (isInfoEnabled())
+ {
+ log.info(interpolate(object, params));
+ }
+ }
+
+ public void info(Object object, Throwable t, Object... params)
+ {
+ if (isInfoEnabled())
+ {
+ log.info(interpolate(object, params), t);
+ }
+ }
+
+ public void warn(Object object, Object... params)
+ {
+ if (isWarnEnabled())
+ {
+ log.warn(interpolate(object, params));
+ }
+ }
+
+ public void warn(Object object, Throwable t, Object... params)
+ {
+ if (isWarnEnabled())
+ {
+ log.warn(interpolate(object, params), t);
+ }
+ }
+
+ public void error(Object object, Object... params)
+ {
+ if (isErrorEnabled())
+ {
+ log.error(interpolate(object, params));
+ }
+ }
+
+ public void error(Object object, Throwable t, Object... params)
+ {
+ if (isErrorEnabled())
+ {
+ log.error(interpolate(object, params), t);
+ }
+ }
+
+ public void fatal(Object object, Object... params)
+ {
+ if (isFatalEnabled())
+ {
+ log.fatal(interpolate(object, params));
+ }
+ }
+
+ public void fatal(Object object, Throwable t, Object... params)
+ {
+ if (isFatalEnabled())
+ {
+ log.fatal(interpolate(object, params), t);
+ }
+ }
+
+ private Object interpolate(Object message, Object... params)
+ {
+ Object interpolatedMessage = message;
+ if (params.length > 0)
+ {
+ interpolatedMessage = MessageFormat.format(message.toString(), params);
+ }
+ return interpolatedMessage;
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ category = (String) in.readObject();
+ log = Logging.getLogProvider(category, true);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeObject(category);
+ }
+
+}
Property changes on: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/LogImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/LogProvider.java
===================================================================
--- extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/LogProvider.java (rev 0)
+++ extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/LogProvider.java 2009-03-16 10:58:56 UTC (rev 2032)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.log;
+
+/**
+ *
+ * @author Gavin King
+ *
+ */
+public interface LogProvider
+{
+ public void trace(Object object);
+ public void trace(Object object, Throwable t);
+ public void debug(Object object);
+ public void debug(Object object, Throwable t);
+ public void info(Object object);
+ public void info(Object object, Throwable t);
+ public void warn(Object object);
+ public void warn(Object object, Throwable t);
+ public void error(Object object);
+ public void error(Object object, Throwable t);
+ public void fatal(Object object);
+ public void fatal(Object object, Throwable t);
+ public boolean isTraceEnabled();
+ public boolean isDebugEnabled();
+ public boolean isInfoEnabled();
+ public boolean isWarnEnabled();
+ public boolean isErrorEnabled();
+ public boolean isFatalEnabled();
+}
Property changes on: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/LogProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Logging.java
===================================================================
--- extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Logging.java (rev 0)
+++ extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Logging.java 2009-03-16 10:58:56 UTC (rev 2032)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.log;
+
+/**
+ *
+ * @author Gavin King
+ *
+ */
+public class Logging
+{
+ private static final boolean isLog4JAvailable;
+
+ static
+ {
+ boolean available;
+ try
+ {
+ Class.forName("org.apache.log4j.Logger");
+ available = true;
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ available = false;
+ }
+ isLog4JAvailable = available;
+ }
+
+ public static Log getLog(String category)
+ {
+ return new LogImpl(category);
+ }
+
+ public static Log getLog(Class<?> clazz)
+ {
+ return new LogImpl(clazz.getName());
+ }
+
+ static LogProvider getLogProvider(String category, boolean wrapped)
+ {
+ return isLog4JAvailable ? new Log4JProvider(category, wrapped) : new JDKProvider(category, wrapped);
+ }
+
+ public static LogProvider getLogProvider(Class<?> clazz)
+ {
+ return getLogProvider(clazz.getName(), false);
+ }
+
+}
Property changes on: extensions/trunk/logging/src/main/java/org/jboss/webbeans/log/Logging.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2031 - in ri/tags/webbeans-core-1.0.0.BETA1: src/main/java/org/jboss/webbeans/util and 7 other directories.
by webbeans-commits@lists.jboss.org
Author: vitold
Date: 2009-03-16 06:57:55 -0400 (Mon, 16 Mar 2009)
New Revision: 2031
Added:
ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/
ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/ClassReceiver.java
ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/ParseXmlHelper.java
ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/XmlConstants.java
ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java
ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/com/
ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/com/mydomain/
ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/com/mydomain/myapp/
ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/com/mydomain/myapp/Order.java
ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/org/jboss/webbeans/test/unit/xml/XmlParserImplTest.java
Modified:
ri/tags/webbeans-core-1.0.0.BETA1/pom.xml
ri/tags/webbeans-core-1.0.0.BETA1/src/test/resources/org/jboss/webbeans/test/unit/xml/user-defined-beans.xml
Log:
add helper class for parsing beans.xml, test class for it, modify user-defined-beans.xml
Modified: ri/tags/webbeans-core-1.0.0.BETA1/pom.xml
===================================================================
--- ri/tags/webbeans-core-1.0.0.BETA1/pom.xml 2009-03-16 10:57:48 UTC (rev 2030)
+++ ri/tags/webbeans-core-1.0.0.BETA1/pom.xml 2009-03-16 10:57:55 UTC (rev 2031)
@@ -10,7 +10,7 @@
<version>1.0.0.BETA1</version>
<name>Web Beans Core</name>
<dependencies>
-
+
<dependency>
<groupId>org.jboss.webbeans</groupId>
<artifactId>jsr299-api</artifactId>
@@ -82,8 +82,14 @@
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
-
+
<dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ </dependency>
+
+ <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
Added: ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/ClassReceiver.java
===================================================================
--- ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/ClassReceiver.java (rev 0)
+++ ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/ClassReceiver.java 2009-03-16 10:57:55 UTC (rev 2031)
@@ -0,0 +1,12 @@
+package org.jboss.webbeans.util.xml;
+
+import java.lang.reflect.AnnotatedElement;
+
+import org.dom4j.Element;
+
+public interface ClassReceiver
+{
+ boolean accept(Element element);
+
+ AnnotatedElement reciveClass(Element element);
+}
Added: ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/ParseXmlHelper.java
===================================================================
--- ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/ParseXmlHelper.java (rev 0)
+++ ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/ParseXmlHelper.java 2009-03-16 10:57:55 UTC (rev 2031)
@@ -0,0 +1,209 @@
+package org.jboss.webbeans.util.xml;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.inject.DefinitionException;
+
+import org.dom4j.Element;
+
+public class ParseXmlHelper
+{
+ private static List<ClassReceiver> receivers;
+
+ static
+ {
+ receivers = initializeReceivers();
+ }
+
+ public static Set<AnnotatedElement> getBeanClasses(List<Element> beans)
+ {
+ Set<AnnotatedElement> result = new HashSet<AnnotatedElement>();
+
+ for (Element bean : beans)
+ result.add(reciveBeanClass(bean));
+
+ return result;
+ }
+
+ private static AnnotatedElement reciveBeanClass(Element element)
+ {
+ for (ClassReceiver receiver : receivers)
+ {
+ if (receiver.accept(element))
+ {
+ return receiver.reciveClass(element);
+ }
+ }
+
+ throw new DefinitionException("definition of a bean " + element.getName() + " is incorrect");
+ }
+
+ private static List<ClassReceiver> initializeReceivers()
+ {
+ List<ClassReceiver> receivers = new ArrayList<ClassReceiver>();
+
+ ClassReceiver jmsResourceClassReceiver = new ClassReceiver()
+ {
+ public boolean accept(Element element)
+ {
+ return isJMSResource(element);
+ }
+
+ public AnnotatedElement reciveClass(Element element)
+ {
+ return reciveJMSResourceClass(element);
+ }
+
+ };
+ ClassReceiver resourceClassReceiver = new ClassReceiver()
+ {
+ public boolean accept(Element element)
+ {
+ return isResource(element);
+ }
+
+ public AnnotatedElement reciveClass(Element element)
+ {
+ return reciveResourceClass(element);
+ }
+
+ };
+ ClassReceiver sessionBeanClassReceiver = new ClassReceiver()
+ {
+ public boolean accept(Element element)
+ {
+ return isSessionBean(element);
+ }
+
+ public AnnotatedElement reciveClass(Element element)
+ {
+ return reciveSessionBeanClass(element);
+ }
+
+ };
+ ClassReceiver simpleBeanClassReceiver = new ClassReceiver()
+ {
+ public boolean accept(Element element)
+ {
+ return isSimpleBean(element);
+ }
+
+ public AnnotatedElement reciveClass(Element element)
+ {
+ return reciveSimpleBeanClass(element);
+ }
+
+ };
+
+ receivers.add(jmsResourceClassReceiver);
+ receivers.add(resourceClassReceiver);
+ receivers.add(sessionBeanClassReceiver);
+ receivers.add(simpleBeanClassReceiver);
+
+ return receivers;
+ }
+
+ private static boolean isResource(Element element)
+ {
+ Iterator<?> elIterator = element.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element child = (Element) elIterator.next();
+ if (child.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE) &&
+ (child.getName().equalsIgnoreCase(XmlConstants.RESOURCE) ||
+ child.getName().equalsIgnoreCase(XmlConstants.PERSISTENCE_CONTEXT) ||
+ child.getName().equalsIgnoreCase(XmlConstants.PERSISTENCE_UNIT) ||
+ child.getName().equalsIgnoreCase(XmlConstants.EJB) ||
+ child.getName().equalsIgnoreCase(XmlConstants.WEB_SERVICE_REF)))
+ return true;
+ }
+ return false;
+ }
+
+ private static AnnotatedElement reciveResourceClass(Element element)
+ {
+ // TODO:
+ return null;
+ }
+
+ private static boolean isJMSResource(Element element)
+ {
+ if (element.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE) &&
+ (element.getName().equalsIgnoreCase(XmlConstants.TOPIC) ||
+ element.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
+ return true;
+ return false;
+ }
+
+ private static AnnotatedElement reciveJMSResourceClass(Element element)
+ {
+ // TODO:
+ return null;
+ }
+
+ private static boolean isSimpleBean(Element element)
+ {
+ Class<?> beanClass = loadClass(element);
+
+ if (!Modifier.isAbstract(beanClass.getModifiers()) &&
+ beanClass.getTypeParameters().length == 0)
+ return true;
+
+ return false;
+ }
+
+ private static AnnotatedElement reciveSimpleBeanClass(Element element)
+ {
+ Class<?> beanClass = loadClass(element);
+
+ if (beanClass.isMemberClass())
+ throw new DefinitionException("class " + beanClass + " is a non-static inner class");
+
+ // if (beanClass.getTypeParameters().length > 0)
+ // throw new DefinitionException("class " + beanClass +
+ // " is a parameterized type");
+
+ // TODO:
+ // boolean isDecorator = false;
+ // if (Modifier.isAbstract(beanClass.getModifiers()) && !isDecorator)
+ // throw new DefinitionException("class " + beanClass +
+ // " is an abstract and not Decorator");
+
+ return beanClass;
+ }
+
+ private static boolean isSessionBean(Element element)
+ {
+ // TODO:
+ return false;
+ }
+
+ private static AnnotatedElement reciveSessionBeanClass(Element element)
+ {
+ // TODO:
+ return null;
+ }
+
+ private static Class<?> loadClass(Element element)
+ {
+ String beanUri = element.getNamespace().getURI();
+ String packageName = beanUri.replaceFirst(XmlConstants.URN_PREFIX, "");
+ String classPath = packageName + "." + element.getName();
+
+ try
+ {
+ return Class.forName(classPath);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new DefinitionException("class " + classPath + " not found");
+ }
+
+ }
+}
Added: ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/XmlConstants.java
===================================================================
--- ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/XmlConstants.java (rev 0)
+++ ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/XmlConstants.java 2009-03-16 10:57:55 UTC (rev 2031)
@@ -0,0 +1,34 @@
+package org.jboss.webbeans.util.xml;
+
+public class XmlConstants
+{
+ public static final String JAVA_EE_NAMESPACE = "urn:java:ee";
+
+ public static final String DEPLOY = "Deploy";
+
+ public static final String INTERCEPTORS = "Interceptors";
+
+ public static final String DECORATORS = "Decorators";
+
+ public static final String BINDING_TYPE = "BindingType";
+
+ public static final String INTERCEPTOR_BINDING_TYPE = "InterceptorBindingType";
+
+ public static final String STEREOTYPE = "Stereotype";
+
+ public static final String RESOURCE = "Resource";
+
+ public static final String PERSISTENCE_CONTEXT = "PersistenceContext";
+
+ public static final String PERSISTENCE_UNIT = "PersistenceUnit";
+
+ public static final String EJB = "EJB";
+
+ public static final String WEB_SERVICE_REF = "WebServiceRef";
+
+ public static final String TOPIC = "Topic";
+
+ public static final String QUEUE = "Queue";
+
+ public static final String URN_PREFIX = "urn:java:";
+}
Added: ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java
===================================================================
--- ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java (rev 0)
+++ ri/tags/webbeans-core-1.0.0.BETA1/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java 2009-03-16 10:57:55 UTC (rev 2031)
@@ -0,0 +1,93 @@
+package org.jboss.webbeans.util.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.AnnotatedElement;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+public class XmlParserImpl // implements XmlParser
+{
+
+ private static Logger log = Logger.getLogger(XmlParserImpl.class);
+
+ public Set<AnnotatedElement> parse(Set<URL> xmls)
+ {
+ Set<AnnotatedElement> result = new HashSet<AnnotatedElement>();
+
+ for (URL url : xmls)
+ {
+ try
+ {
+ InputStream xmlStream;
+
+ xmlStream = url.openStream();
+ SAXReader reader = new SAXReader();
+ Document document = reader.read(xmlStream);
+ List<Element> beanElements = findBeans(document);
+ result.addAll(ParseXmlHelper.getBeanClasses(beanElements));
+ }
+ catch (IOException e)
+ {
+ log.debug("Can not open stream for " + url, e);
+ }
+ catch (DocumentException e)
+ {
+ log.debug("Error during the processing of a DOM4J document for " + url, e);
+ }
+ }
+ return result;
+ }
+
+ private List<Element> findBeans(Document document)
+ {
+ List<Element> beans = new ArrayList<Element>();
+
+ Element root = document.getRootElement();
+
+ Iterator<?> elIterator = root.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element element = (Element) elIterator.next();
+ if (checkElementName(element) && checkElementChildrenNames(element))
+ beans.add(element);
+ }
+
+ return beans;
+ }
+
+ private boolean checkElementName(Element element)
+ {
+ if (element.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE) &&
+ (element.getName().equalsIgnoreCase(XmlConstants.DEPLOY) ||
+ element.getName().equalsIgnoreCase(XmlConstants.INTERCEPTORS) ||
+ element.getName().equalsIgnoreCase(XmlConstants.DECORATORS)))
+ return false;
+ return true;
+ }
+
+ private boolean checkElementChildrenNames(Element element)
+ {
+ Iterator<?> elIterator = element.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element child = (Element) elIterator.next();
+ if (child.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE) &&
+ (child.getName().equalsIgnoreCase(XmlConstants.BINDING_TYPE) ||
+ child.getName().equalsIgnoreCase(XmlConstants.INTERCEPTOR_BINDING_TYPE) ||
+ child.getName().equalsIgnoreCase(XmlConstants.STEREOTYPE)))
+ return false;
+ }
+ return true;
+ }
+}
Added: ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/com/mydomain/myapp/Order.java
===================================================================
--- ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/com/mydomain/myapp/Order.java (rev 0)
+++ ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/com/mydomain/myapp/Order.java 2009-03-16 10:57:55 UTC (rev 2031)
@@ -0,0 +1,6 @@
+package com.mydomain.myapp;
+
+public class Order
+{
+
+}
Added: ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/org/jboss/webbeans/test/unit/xml/XmlParserImplTest.java
===================================================================
--- ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/org/jboss/webbeans/test/unit/xml/XmlParserImplTest.java (rev 0)
+++ ri/tags/webbeans-core-1.0.0.BETA1/src/test/java/org/jboss/webbeans/test/unit/xml/XmlParserImplTest.java 2009-03-16 10:57:55 UTC (rev 2031)
@@ -0,0 +1,56 @@
+package org.jboss.webbeans.test.unit.xml;
+
+import java.lang.reflect.AnnotatedElement;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.webbeans.test.unit.AbstractTest;
+import org.jboss.webbeans.util.xml.XmlParserImpl;
+//import org.jboss.webbeans.tck.impl.SpecAssertion;
+import org.testng.annotations.Test;
+
+import com.mydomain.myapp.Order;
+
+public class XmlParserImplTest extends AbstractTest
+{
+ @Test
+ public void testParse()
+ {
+ Set<URL> xmls = new HashSet<URL>();
+ Iterable<URL> urls = getResources("user-defined-beans.xml");
+
+ for (URL url : urls)
+ xmls.add(url);
+
+ XmlParserImpl parser = new XmlParserImpl();
+ Set<AnnotatedElement> aSet = parser.parse(xmls);
+
+ for(AnnotatedElement aElement : aSet){
+ assert aElement.equals(Order.class);
+ }
+ assert aSet.size() == 1;
+ }
+}
+
+/*
+<Beans xmlns="urn:java:ee" xmlns:myapp="urn:java:com.mydomain.myapp"
+xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml">
+<Deploy>
+ <Standard />
+ <Production />
+ <test:AnotherDeploymentType />
+</Deploy>
+<myapp:Order>
+ <ConversationScoped />
+ <myapp:PaymentProcessor>
+ <myapp:Asynchronous />
+ </myapp:PaymentProcessor>
+ <myapp:User />
+</myapp:Order>
+<myapp:Login>
+ <ConversationScoped />
+ <BindingType />
+</myapp:Login>
+</Beans>
+*/
Modified: ri/tags/webbeans-core-1.0.0.BETA1/src/test/resources/org/jboss/webbeans/test/unit/xml/user-defined-beans.xml
===================================================================
--- ri/tags/webbeans-core-1.0.0.BETA1/src/test/resources/org/jboss/webbeans/test/unit/xml/user-defined-beans.xml 2009-03-16 10:57:48 UTC (rev 2030)
+++ ri/tags/webbeans-core-1.0.0.BETA1/src/test/resources/org/jboss/webbeans/test/unit/xml/user-defined-beans.xml 2009-03-16 10:57:55 UTC (rev 2031)
@@ -1,8 +1,19 @@
-<Beans xmlns="urn:java:ee"
- xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml">
- <Deploy>
- <Standard />
- <Production />
- <test:AnotherDeploymentType />
- </Deploy>
-</Beans>
+<Beans xmlns="urn:java:ee" xmlns:myapp="urn:java:com.mydomain.myapp"
+ xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml">
+ <Deploy>
+ <Standard />
+ <Production />
+ <test:AnotherDeploymentType />
+ </Deploy>
+ <myapp:Order>
+ <ConversationScoped />
+ <myapp:PaymentProcessor>
+ <myapp:Asynchronous />
+ </myapp:PaymentProcessor>
+ <myapp:User />
+ </myapp:Order>
+ <myapp:Login>
+ <ConversationScoped />
+ <BindingType />
+ </myapp:Login>
+</Beans>
\ No newline at end of file
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2030 - in ri/trunk: impl/src/main/java/org/jboss/webbeans and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2009-03-16 06:57:48 -0400 (Mon, 16 Mar 2009)
New Revision: 2030
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/log/
Modified:
ri/trunk/impl/pom.xml
ri/trunk/version-matrix/pom.xml
Log:
Moved logging to an extensions project.
Modified: ri/trunk/impl/pom.xml
===================================================================
--- ri/trunk/impl/pom.xml 2009-03-16 10:23:32 UTC (rev 2029)
+++ ri/trunk/impl/pom.xml 2009-03-16 10:57:48 UTC (rev 2030)
@@ -22,6 +22,11 @@
</dependency>
<dependency>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>webbeans-logging</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
Modified: ri/trunk/version-matrix/pom.xml
===================================================================
--- ri/trunk/version-matrix/pom.xml 2009-03-16 10:23:32 UTC (rev 2029)
+++ ri/trunk/version-matrix/pom.xml 2009-03-16 10:57:48 UTC (rev 2030)
@@ -226,6 +226,12 @@
</dependency>
<dependency>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>webbeans-logging</artifactId>
+ <version>${webbeans.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss.jsr299.tck</groupId>
<artifactId>jsr299-tck-api</artifactId>
<version>${jsr299.tck.version}</version>
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2029 - in extensions/trunk: logging and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2009-03-16 06:23:32 -0400 (Mon, 16 Mar 2009)
New Revision: 2029
Added:
extensions/trunk/logging/
extensions/trunk/logging/pom.xml
extensions/trunk/logging/src/
extensions/trunk/logging/src/main/
extensions/trunk/logging/src/main/java/
Log:
Initial structure for Logging project.
Added: extensions/trunk/logging/pom.xml
===================================================================
--- extensions/trunk/logging/pom.xml (rev 0)
+++ extensions/trunk/logging/pom.xml 2009-03-16 10:23:32 UTC (rev 2029)
@@ -0,0 +1,37 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>webbeans-parent</artifactId>
+ <groupId>org.jboss.webbeans</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>webbeans-logging</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Web Beans Logging</name>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ <classifier>jdk15</classifier>
+ <exclusions>
+ <exclusion>
+ <artifactId>junit</artifactId>
+ <groupId>junit</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ </build>
+
+</project>
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2028 - in tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition: scope and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2009-03-16 04:18:31 -0400 (Mon, 16 Mar 2009)
New Revision: 2028
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/binding/EnglishBorderCollie.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/scope/EnglishBorderCollie.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/stereotype/EnglishBorderCollie.java
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/binding/BindingDefinitionTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/scope/ScopeDefinitionTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/stereotype/StereotypeDefinitionTest.java
Log:
implemented some more section 4.1 quests
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/binding/BindingDefinitionTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/binding/BindingDefinitionTest.java 2009-03-16 08:12:30 UTC (rev 2027)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/binding/BindingDefinitionTest.java 2009-03-16 08:18:31 UTC (rev 2028)
@@ -157,6 +157,7 @@
}
@Test(groups = { "injection", "producerMethod" })
+ @SpecAssertion(section = "unknown", id = "unknown")
public void testMethodWithBindingAnnotationsOnParametersAreInjected() throws Exception
{
new RunInDependentContext()
@@ -218,5 +219,14 @@
Hairy hairy = (Hairy) binding;
assert hairy.clipped();
}
+
+ @Test
+ @SpecAssertion(section = "4.1", id = "ag")
+ public void testBindingDeclaredInheritedIsIndirectlyInherited()
+ {
+ Set<? extends Annotation> bindings = getCurrentManager().resolveByType(EnglishBorderCollie.class, new HairyBinding(false)).iterator().next().getBindings();
+ assert bindings.size() == 1;
+ assert bindings.iterator().next().annotationType().equals(Hairy.class);
+ }
}
\ No newline at end of file
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/binding/EnglishBorderCollie.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/binding/EnglishBorderCollie.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/binding/EnglishBorderCollie.java 2009-03-16 08:18:31 UTC (rev 2028)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.definition.binding;
+
+class EnglishBorderCollie extends BorderCollie
+{
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/scope/EnglishBorderCollie.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/scope/EnglishBorderCollie.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/scope/EnglishBorderCollie.java 2009-03-16 08:18:31 UTC (rev 2028)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.definition.scope;
+
+class EnglishBorderCollie extends BorderCollie
+{
+
+}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/scope/ScopeDefinitionTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/scope/ScopeDefinitionTest.java 2009-03-16 08:12:30 UTC (rev 2027)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/scope/ScopeDefinitionTest.java 2009-03-16 08:18:31 UTC (rev 2028)
@@ -108,7 +108,6 @@
@Test @SpecAssertion(section="4.1", id = "ba")
public void testScopeTypeDeclaredInheritedIsInherited() throws Exception
{
- assert getCurrentManager().resolveByType(BorderCollie.class).size() == 1;
assert getCurrentManager().resolveByType(BorderCollie.class).iterator().next().getScopeType().equals(RequestScoped.class);
}
@@ -132,4 +131,12 @@
assert getCurrentManager().resolveByType(GoldenLabrador.class).iterator().next().getScopeType().equals(Dependent.class);
}
+ @Test
+ @SpecAssertion(section = "4.1", id = "bc")
+ public void testScopeTypeDeclaredInheritedIsIndirectlyInherited()
+ {
+
+ assert getCurrentManager().resolveByType(EnglishBorderCollie.class).iterator().next().getScopeType().equals(RequestScoped.class);
+ }
+
}
\ No newline at end of file
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/stereotype/EnglishBorderCollie.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/stereotype/EnglishBorderCollie.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/stereotype/EnglishBorderCollie.java 2009-03-16 08:18:31 UTC (rev 2028)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.definition.stereotype;
+
+class EnglishBorderCollie extends BorderCollie
+{
+
+}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/stereotype/StereotypeDefinitionTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/stereotype/StereotypeDefinitionTest.java 2009-03-16 08:12:30 UTC (rev 2027)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/stereotype/StereotypeDefinitionTest.java 2009-03-16 08:18:31 UTC (rev 2028)
@@ -148,7 +148,6 @@
@SpecAssertion(section = "4.1", id = "ab")
public void testStereotypeDeclaredInheritedIsInherited() throws Exception
{
- assert getCurrentManager().resolveByType(BorderCollie.class).size() == 1;
assert getCurrentManager().resolveByType(BorderCollie.class).iterator().next().getScopeType().equals(RequestScoped.class);
}
@@ -159,5 +158,12 @@
assert getCurrentManager().resolveByType(ShetlandPony.class).size() == 1;
assert getCurrentManager().resolveByType(ShetlandPony.class).iterator().next().getDeploymentType().equals(Production.class);
}
+
+ @Test
+ @SpecAssertion(section = "4.1", id = "ah")
+ public void testStereotypeDeclaredInheritedIsIndirectlyInherited()
+ {
+ assert getCurrentManager().resolveByType(EnglishBorderCollie.class).iterator().next().getScopeType().equals(RequestScoped.class);
+ }
}
15 years, 10 months