You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2015/09/25 12:42:48 UTC
[13/33] tomee git commit: Align SNAPSHOT versions & reformat examples
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/QueryAndPostCommand.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/QueryAndPostCommand.java b/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/QueryAndPostCommand.java
index 8af0a3f..c72bbaf 100644
--- a/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/QueryAndPostCommand.java
+++ b/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/QueryAndPostCommand.java
@@ -1,48 +1,48 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.client.command.impl;
-
-import jug.client.command.api.AbstractCommand;
-import jug.client.command.api.Command;
-
-import javax.ws.rs.core.Response;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public abstract class QueryAndPostCommand extends AbstractCommand {
-
- private static final Pattern PATTERN = Pattern.compile(" \\[(.*),(.*)\\]");
-
- @Override
- protected Response invoke(final String cmd) {
- final Matcher matcher = PATTERN.matcher(cmd.substring(getClass().getAnnotation(Command.class).name().length()));
- if (!matcher.matches() || matcher.groupCount() != 2) {
- System.err.println("'" + cmd + "' doesn't match command usage");
- return null;
- }
-
- return client.path(getPath()).query(getName(), matcher.group(1).trim()).post(prePost(matcher.group(2).trim()));
- }
-
- protected String prePost(final String post) {
- return post;
- }
-
- protected abstract String getName();
-
- protected abstract String getPath();
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.client.command.impl;
+
+import jug.client.command.api.AbstractCommand;
+import jug.client.command.api.Command;
+
+import javax.ws.rs.core.Response;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public abstract class QueryAndPostCommand extends AbstractCommand {
+
+ private static final Pattern PATTERN = Pattern.compile(" \\[(.*),(.*)\\]");
+
+ @Override
+ protected Response invoke(final String cmd) {
+ final Matcher matcher = PATTERN.matcher(cmd.substring(getClass().getAnnotation(Command.class).name().length()));
+ if (!matcher.matches() || matcher.groupCount() != 2) {
+ System.err.println("'" + cmd + "' doesn't match command usage");
+ return null;
+ }
+
+ return client.path(getPath()).query(getName(), matcher.group(1).trim()).post(prePost(matcher.group(2).trim()));
+ }
+
+ protected String prePost(final String post) {
+ return post;
+ }
+
+ protected abstract String getName();
+
+ protected abstract String getPath();
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/ShowPollCommand.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/ShowPollCommand.java b/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/ShowPollCommand.java
index 5313223..9eed651 100644
--- a/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/ShowPollCommand.java
+++ b/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/ShowPollCommand.java
@@ -1,40 +1,40 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.client.command.impl;
-
-import jug.client.command.api.AbstractCommand;
-import jug.client.command.api.Command;
-
-import javax.ws.rs.core.Response;
-
-import static jug.client.command.impl.ShowPollCommand.SHOW_POLL_CMD;
-
-@Command(name = SHOW_POLL_CMD, usage = SHOW_POLL_CMD + " <name>", description = "show a poll")
-public class ShowPollCommand extends AbstractCommand {
-
- public static final String SHOW_POLL_CMD = "show-poll";
-
- @Override
- protected Response invoke(String cmd) {
- if (SHOW_POLL_CMD.length() + 1 >= cmd.length()) {
- System.err.println("please specify a poll name");
- return null;
- }
-
- return client.path("api/subject/find/".concat(cmd.substring(SHOW_POLL_CMD.length() + 1))).get();
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.client.command.impl;
+
+import jug.client.command.api.AbstractCommand;
+import jug.client.command.api.Command;
+
+import javax.ws.rs.core.Response;
+
+import static jug.client.command.impl.ShowPollCommand.SHOW_POLL_CMD;
+
+@Command(name = SHOW_POLL_CMD, usage = SHOW_POLL_CMD + " <name>", description = "show a poll")
+public class ShowPollCommand extends AbstractCommand {
+
+ public static final String SHOW_POLL_CMD = "show-poll";
+
+ @Override
+ protected Response invoke(String cmd) {
+ if (SHOW_POLL_CMD.length() + 1 >= cmd.length()) {
+ System.err.println("please specify a poll name");
+ return null;
+ }
+
+ return client.path("api/subject/find/".concat(cmd.substring(SHOW_POLL_CMD.length() + 1))).get();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/SwitchClientCommand.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/SwitchClientCommand.java b/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/SwitchClientCommand.java
index 3bf715b..d08fb76 100644
--- a/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/SwitchClientCommand.java
+++ b/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/SwitchClientCommand.java
@@ -1,47 +1,47 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.client.command.impl;
-
-import jug.client.command.api.AbstractCommand;
-import jug.client.command.api.Command;
-import jug.client.util.ClientNameHolder;
-
-import javax.ws.rs.core.Response;
-import java.util.Map;
-
-@Command(name = "client", usage = "client <name>", description = "change client")
-public class SwitchClientCommand extends AbstractCommand {
-
- private Map<String, Class<?>> commands;
-
- @Override
- public void execute(final String cmd) {
- if (cmd.length() <= "client ".length()) {
- System.err.println("please specify a client name (client1 or client2)");
- return;
- }
-
- final String client = cmd.substring(7);
- ClientNameHolder.setCurrent(client);
- }
-
- @Override
- protected Response invoke(String cmd) {
- return null;
- }
-}
-
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.client.command.impl;
+
+import jug.client.command.api.AbstractCommand;
+import jug.client.command.api.Command;
+import jug.client.util.ClientNameHolder;
+
+import javax.ws.rs.core.Response;
+import java.util.Map;
+
+@Command(name = "client", usage = "client <name>", description = "change client")
+public class SwitchClientCommand extends AbstractCommand {
+
+ private Map<String, Class<?>> commands;
+
+ @Override
+ public void execute(final String cmd) {
+ if (cmd.length() <= "client ".length()) {
+ System.err.println("please specify a client name (client1 or client2)");
+ return;
+ }
+
+ final String client = cmd.substring(7);
+ ClientNameHolder.setCurrent(client);
+ }
+
+ @Override
+ protected Response invoke(String cmd) {
+ return null;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/VoteCommand.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/VoteCommand.java b/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/VoteCommand.java
index c95dfff..d0d271f 100644
--- a/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/VoteCommand.java
+++ b/examples/polling-parent/polling-client/src/main/java/jug/client/command/impl/VoteCommand.java
@@ -1,45 +1,45 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.client.command.impl;
-
-import jug.client.command.api.Command;
-import jug.domain.Value;
-
-@Command(name = "vote", usage = "vote [<subject name>, +1|-1]", description = "vote for a subject")
-public class VoteCommand extends QueryAndPostCommand {
-
- @Override
- protected String getName() {
- return "subject";
- }
-
- @Override
- protected String getPath() {
- return "api/subject/vote";
- }
-
- @Override
- protected String prePost(final String post) {
- if ("+1".equals(post) || "like".equals(post)) {
- return Value.I_LIKE.name();
- }
- if ("-1".equals(post)) {
- return Value.I_DONT_LIKE.name();
- }
- throw new IllegalArgumentException("please use +1 or -1 and not '" + post + "'");
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.client.command.impl;
+
+import jug.client.command.api.Command;
+import jug.domain.Value;
+
+@Command(name = "vote", usage = "vote [<subject name>, +1|-1]", description = "vote for a subject")
+public class VoteCommand extends QueryAndPostCommand {
+
+ @Override
+ protected String getName() {
+ return "subject";
+ }
+
+ @Override
+ protected String getPath() {
+ return "api/subject/vote";
+ }
+
+ @Override
+ protected String prePost(final String post) {
+ if ("+1".equals(post) || "like".equals(post)) {
+ return Value.I_LIKE.name();
+ }
+ if ("-1".equals(post)) {
+ return Value.I_DONT_LIKE.name();
+ }
+ throw new IllegalArgumentException("please use +1 or -1 and not '" + post + "'");
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-client/src/main/java/jug/client/util/ClientNameHolder.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-client/src/main/java/jug/client/util/ClientNameHolder.java b/examples/polling-parent/polling-client/src/main/java/jug/client/util/ClientNameHolder.java
index da5f425..2972a1a 100644
--- a/examples/polling-parent/polling-client/src/main/java/jug/client/util/ClientNameHolder.java
+++ b/examples/polling-parent/polling-client/src/main/java/jug/client/util/ClientNameHolder.java
@@ -1,30 +1,30 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.client.util;
-
-public class ClientNameHolder {
-
- private static String current = null;
-
- public static String getCurrent() {
- return current;
- }
-
- public static void setCurrent(String current) {
- ClientNameHolder.current = current;
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.client.util;
+
+public class ClientNameHolder {
+
+ private static String current = null;
+
+ public static String getCurrent() {
+ return current;
+ }
+
+ public static void setCurrent(String current) {
+ ClientNameHolder.current = current;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-client/src/main/java/jug/client/util/CommandManager.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-client/src/main/java/jug/client/util/CommandManager.java b/examples/polling-parent/polling-client/src/main/java/jug/client/util/CommandManager.java
index 03a27b9..a56461f 100644
--- a/examples/polling-parent/polling-client/src/main/java/jug/client/util/CommandManager.java
+++ b/examples/polling-parent/polling-client/src/main/java/jug/client/util/CommandManager.java
@@ -1,74 +1,74 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.client.util;
-
-import jug.client.command.api.Command;
-import org.apache.xbean.finder.Annotated;
-import org.apache.xbean.finder.AnnotationFinder;
-import org.apache.xbean.finder.IAnnotationFinder;
-import org.apache.xbean.finder.UrlSet;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class CommandManager {
-
- private static final Logger LOGGER = Logger.getLogger(CommandManager.class.getName());
- private static final Map<String, Class<?>> COMMANDS = new TreeMap<String, Class<?>>();
-
- static {
- final ClassLoader loader = CommandManager.class.getClassLoader();
- try {
- UrlSet urlSet = new UrlSet(loader);
- urlSet = urlSet.exclude(loader);
- urlSet = urlSet.include(CommandManager.class.getProtectionDomain().getCodeSource().getLocation());
-
- final IAnnotationFinder finder = new AnnotationFinder(new ConfigurableClasspathArchive(loader, urlSet.getUrls()));
- for (Annotated<Class<?>> cmd : finder.findMetaAnnotatedClasses(Command.class)) {
- try {
- final Command annotation = cmd.getAnnotation(Command.class);
- final String key = annotation.name();
- if (!COMMANDS.containsKey(key)) {
- COMMANDS.put(key, cmd.get());
- } else {
- LOGGER.warning("command " + key + " already exists, this one will be ignored ( " + annotation.description() + ")");
- }
- } catch (Exception e) {
- // command ignored
- }
- }
- } catch (RuntimeException | IOException e) {
- LOGGER.log(Level.SEVERE, "an error occured while getting commands", e);
- }
- }
-
- public static Map<String, Class<?>> getCommands() {
- return COMMANDS;
- }
-
- public static int size() {
- return COMMANDS.size();
- }
-
- public static Set<String> keys() {
- return COMMANDS.keySet();
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.client.util;
+
+import jug.client.command.api.Command;
+import org.apache.xbean.finder.Annotated;
+import org.apache.xbean.finder.AnnotationFinder;
+import org.apache.xbean.finder.IAnnotationFinder;
+import org.apache.xbean.finder.UrlSet;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class CommandManager {
+
+ private static final Logger LOGGER = Logger.getLogger(CommandManager.class.getName());
+ private static final Map<String, Class<?>> COMMANDS = new TreeMap<String, Class<?>>();
+
+ static {
+ final ClassLoader loader = CommandManager.class.getClassLoader();
+ try {
+ UrlSet urlSet = new UrlSet(loader);
+ urlSet = urlSet.exclude(loader);
+ urlSet = urlSet.include(CommandManager.class.getProtectionDomain().getCodeSource().getLocation());
+
+ final IAnnotationFinder finder = new AnnotationFinder(new ConfigurableClasspathArchive(loader, urlSet.getUrls()));
+ for (Annotated<Class<?>> cmd : finder.findMetaAnnotatedClasses(Command.class)) {
+ try {
+ final Command annotation = cmd.getAnnotation(Command.class);
+ final String key = annotation.name();
+ if (!COMMANDS.containsKey(key)) {
+ COMMANDS.put(key, cmd.get());
+ } else {
+ LOGGER.warning("command " + key + " already exists, this one will be ignored ( " + annotation.description() + ")");
+ }
+ } catch (Exception e) {
+ // command ignored
+ }
+ }
+ } catch (RuntimeException | IOException e) {
+ LOGGER.log(Level.SEVERE, "an error occured while getting commands", e);
+ }
+ }
+
+ public static Map<String, Class<?>> getCommands() {
+ return COMMANDS;
+ }
+
+ public static int size() {
+ return COMMANDS.size();
+ }
+
+ public static Set<String> keys() {
+ return COMMANDS.keySet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-client/src/main/java/jug/client/util/ConfigurableClasspathArchive.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-client/src/main/java/jug/client/util/ConfigurableClasspathArchive.java b/examples/polling-parent/polling-client/src/main/java/jug/client/util/ConfigurableClasspathArchive.java
index fb9b090..e695fc5 100644
--- a/examples/polling-parent/polling-client/src/main/java/jug/client/util/ConfigurableClasspathArchive.java
+++ b/examples/polling-parent/polling-client/src/main/java/jug/client/util/ConfigurableClasspathArchive.java
@@ -1,196 +1,196 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.client.util;
-
-import org.apache.xbean.finder.archive.Archive;
-import org.apache.xbean.finder.archive.ClassesArchive;
-import org.apache.xbean.finder.archive.ClasspathArchive;
-import org.apache.xbean.finder.archive.CompositeArchive;
-import org.apache.xbean.finder.archive.FilteredArchive;
-import org.apache.xbean.finder.filter.Filter;
-import org.apache.xbean.finder.filter.FilterList;
-import org.apache.xbean.finder.filter.PackageFilter;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class ConfigurableClasspathArchive extends CompositeArchive {
-
- private static final SAXParserFactory SAX_FACTORY = SAXParserFactory.newInstance();
- private static final String SCAN_XML = "META-INF/scan.xml";
-
- public ConfigurableClasspathArchive(final ClassLoader loader, final Iterable<URL> urls) {
- super(archive(loader, urls, true));
- }
-
- public static List<Archive> archive(final ClassLoader loader, final Iterable<URL> urls, boolean forceDescriptor) {
- final List<Archive> archives = new ArrayList<Archive>();
- for (URL location : urls) {
- try {
- archives.add(archive(loader, location, true));
- } catch (Exception e) {
- // ignored
- }
- }
- return archives;
- }
-
- public static Archive archive(final ClassLoader loader, final URL location, boolean forceDescriptor) {
- try {
- URL scanXml = loader.getResource(SCAN_XML);
- if (scanXml == null && !forceDescriptor) {
- return ClasspathArchive.archive(loader, location);
- } else if (scanXml == null) {
- return new ClassesArchive();
- }
-
- // read descriptors
- ScanHandler scan;
- if (scanXml != null) {
- scan = read(scanXml);
- } else {
- scan = new ScanHandler();
- }
-
- final Archive packageArchive = packageArchive(scan.getPackages(), loader, location);
- final Archive classesArchive = classesArchive(scan.getPackages(), scan.getClasses(), loader);
-
- if (packageArchive != null && classesArchive != null) {
- return new CompositeArchive(classesArchive, packageArchive);
- } else if (packageArchive != null) {
- return packageArchive;
- }
- return classesArchive;
- } catch (IOException e) {
- if (forceDescriptor) {
- return new ClassesArchive();
- }
- return ClasspathArchive.archive(loader, location);
- }
- }
-
- public static Archive packageArchive(final Set<String> packageNames, final ClassLoader loader, final URL url) {
- if (!packageNames.isEmpty()) {
- return new FilteredArchive(ClasspathArchive.archive(loader, url), filters(packageNames));
- }
- return null;
- }
-
- private static Filter filters(final Set<String> packageNames) {
- final List<Filter> filters = new ArrayList<Filter>();
- for (String packageName : packageNames) {
- filters.add(new PackageFilter(packageName));
- }
- return new FilterList(filters);
- }
-
- public static Archive classesArchive(final Set<String> packages, final Set<String> classnames, final ClassLoader loader) {
- Class<?>[] classes = new Class<?>[classnames.size()];
- int i = 0;
- for (String clazz : classnames) {
- // skip classes managed by package filtering
- if (packages != null && clazzInPackage(packages, clazz)) {
- continue;
- }
-
- try {
- classes[i++] = loader.loadClass(clazz);
- } catch (ClassNotFoundException e) {
- // ignored
- }
- }
-
- if (i != classes.length) { // shouldn't occur
- final Class<?>[] updatedClasses = new Class<?>[i];
- System.arraycopy(classes, 0, updatedClasses, 0, i);
- classes = updatedClasses;
- }
-
- return new ClassesArchive(classes);
- }
-
- private static boolean clazzInPackage(final Collection<String> packagename, final String clazz) {
- for (String str : packagename) {
- if (clazz.startsWith(str)) {
- return true;
- }
- }
- return false;
- }
-
- public static ScanHandler read(final URL scanXml) throws IOException {
- final SAXParser parser;
- try {
- synchronized (SAX_FACTORY) {
- parser = SAX_FACTORY.newSAXParser();
- }
- final ScanHandler handler = new ScanHandler();
- parser.parse(new BufferedInputStream(scanXml.openStream()), handler);
- return handler;
- } catch (Exception e) {
- throw new IOException("can't parse " + scanXml.toExternalForm());
- }
- }
-
- public static final class ScanHandler extends DefaultHandler {
-
- private final Set<String> classes = new HashSet<String>();
- private final Set<String> packages = new HashSet<String>();
- private Set<String> current = null;
-
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- if (qName.equals("class")) {
- current = classes;
- } else if (qName.equals("package")) {
- current = packages;
- }
- }
-
- @Override
- public void characters(char ch[], int start, int length) throws SAXException {
- if (current != null) {
- current.add(new String(ch, start, length));
- }
- }
-
- @Override
- public void endElement(final String uri, final String localName, final String qName) throws SAXException {
- current = null;
- }
-
- public Set<String> getPackages() {
- return packages;
- }
-
- public Set<String> getClasses() {
- return classes;
- }
- }
-}
-
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.client.util;
+
+import org.apache.xbean.finder.archive.Archive;
+import org.apache.xbean.finder.archive.ClassesArchive;
+import org.apache.xbean.finder.archive.ClasspathArchive;
+import org.apache.xbean.finder.archive.CompositeArchive;
+import org.apache.xbean.finder.archive.FilteredArchive;
+import org.apache.xbean.finder.filter.Filter;
+import org.apache.xbean.finder.filter.FilterList;
+import org.apache.xbean.finder.filter.PackageFilter;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class ConfigurableClasspathArchive extends CompositeArchive {
+
+ private static final SAXParserFactory SAX_FACTORY = SAXParserFactory.newInstance();
+ private static final String SCAN_XML = "META-INF/scan.xml";
+
+ public ConfigurableClasspathArchive(final ClassLoader loader, final Iterable<URL> urls) {
+ super(archive(loader, urls, true));
+ }
+
+ public static List<Archive> archive(final ClassLoader loader, final Iterable<URL> urls, boolean forceDescriptor) {
+ final List<Archive> archives = new ArrayList<Archive>();
+ for (URL location : urls) {
+ try {
+ archives.add(archive(loader, location, true));
+ } catch (Exception e) {
+ // ignored
+ }
+ }
+ return archives;
+ }
+
+ public static Archive archive(final ClassLoader loader, final URL location, boolean forceDescriptor) {
+ try {
+ URL scanXml = loader.getResource(SCAN_XML);
+ if (scanXml == null && !forceDescriptor) {
+ return ClasspathArchive.archive(loader, location);
+ } else if (scanXml == null) {
+ return new ClassesArchive();
+ }
+
+ // read descriptors
+ ScanHandler scan;
+ if (scanXml != null) {
+ scan = read(scanXml);
+ } else {
+ scan = new ScanHandler();
+ }
+
+ final Archive packageArchive = packageArchive(scan.getPackages(), loader, location);
+ final Archive classesArchive = classesArchive(scan.getPackages(), scan.getClasses(), loader);
+
+ if (packageArchive != null && classesArchive != null) {
+ return new CompositeArchive(classesArchive, packageArchive);
+ } else if (packageArchive != null) {
+ return packageArchive;
+ }
+ return classesArchive;
+ } catch (IOException e) {
+ if (forceDescriptor) {
+ return new ClassesArchive();
+ }
+ return ClasspathArchive.archive(loader, location);
+ }
+ }
+
+ public static Archive packageArchive(final Set<String> packageNames, final ClassLoader loader, final URL url) {
+ if (!packageNames.isEmpty()) {
+ return new FilteredArchive(ClasspathArchive.archive(loader, url), filters(packageNames));
+ }
+ return null;
+ }
+
+ private static Filter filters(final Set<String> packageNames) {
+ final List<Filter> filters = new ArrayList<Filter>();
+ for (String packageName : packageNames) {
+ filters.add(new PackageFilter(packageName));
+ }
+ return new FilterList(filters);
+ }
+
+ public static Archive classesArchive(final Set<String> packages, final Set<String> classnames, final ClassLoader loader) {
+ Class<?>[] classes = new Class<?>[classnames.size()];
+ int i = 0;
+ for (String clazz : classnames) {
+ // skip classes managed by package filtering
+ if (packages != null && clazzInPackage(packages, clazz)) {
+ continue;
+ }
+
+ try {
+ classes[i++] = loader.loadClass(clazz);
+ } catch (ClassNotFoundException e) {
+ // ignored
+ }
+ }
+
+ if (i != classes.length) { // shouldn't occur
+ final Class<?>[] updatedClasses = new Class<?>[i];
+ System.arraycopy(classes, 0, updatedClasses, 0, i);
+ classes = updatedClasses;
+ }
+
+ return new ClassesArchive(classes);
+ }
+
+ private static boolean clazzInPackage(final Collection<String> packagename, final String clazz) {
+ for (String str : packagename) {
+ if (clazz.startsWith(str)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static ScanHandler read(final URL scanXml) throws IOException {
+ final SAXParser parser;
+ try {
+ synchronized (SAX_FACTORY) {
+ parser = SAX_FACTORY.newSAXParser();
+ }
+ final ScanHandler handler = new ScanHandler();
+ parser.parse(new BufferedInputStream(scanXml.openStream()), handler);
+ return handler;
+ } catch (Exception e) {
+ throw new IOException("can't parse " + scanXml.toExternalForm());
+ }
+ }
+
+ public static final class ScanHandler extends DefaultHandler {
+
+ private final Set<String> classes = new HashSet<String>();
+ private final Set<String> packages = new HashSet<String>();
+ private Set<String> current = null;
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ if (qName.equals("class")) {
+ current = classes;
+ } else if (qName.equals("package")) {
+ current = packages;
+ }
+ }
+
+ @Override
+ public void characters(char ch[], int start, int length) throws SAXException {
+ if (current != null) {
+ current.add(new String(ch, start, length));
+ }
+ }
+
+ @Override
+ public void endElement(final String uri, final String localName, final String qName) throws SAXException {
+ current = null;
+ }
+
+ public Set<String> getPackages() {
+ return packages;
+ }
+
+ public Set<String> getClasses() {
+ return classes;
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-core/src/main/java/jug/dao/SubjectDao.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-core/src/main/java/jug/dao/SubjectDao.java b/examples/polling-parent/polling-core/src/main/java/jug/dao/SubjectDao.java
index 2fb6fcb..824ca75 100644
--- a/examples/polling-parent/polling-core/src/main/java/jug/dao/SubjectDao.java
+++ b/examples/polling-parent/polling-core/src/main/java/jug/dao/SubjectDao.java
@@ -1,115 +1,115 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.dao;
-
-import jug.domain.Subject;
-import jug.domain.Value;
-import jug.domain.Vote;
-
-import javax.ejb.Lock;
-import javax.ejb.LockType;
-import javax.ejb.Singleton;
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import java.util.Collection;
-
-@Singleton
-@Lock(LockType.READ)
-public class SubjectDao {
-
- @PersistenceContext(unitName = "polling")
- private EntityManager em;
-
- @Inject
- private ReadSubjectDao readDao;
-
- public Subject create(final String name, final String question) {
- final Subject subject = new Subject();
- subject.setName(name);
- subject.setQuestion(question);
-
- em.persist(subject);
- return subject;
- }
-
- public Subject addVote(final Subject subject, final Vote vote) {
- final Vote foundVote = retrieve(vote, Vote.class, vote.getId());
- final Subject subjectToUpdate = retrieve(subject, Subject.class, subject.getId());
-
- subjectToUpdate.getVotes().add(foundVote);
- return subjectToUpdate;
- }
-
- public Subject findByName(final String name) {
- return readDao.findByName(name);
- }
-
- public Collection<Subject> findAll() {
- return readDao.findAll();
- }
-
- public int subjectLikeVoteNumber(final String subjectName) {
- return subjectVoteNumber(subjectName, Value.I_LIKE);
- }
-
- public int subjectNotLikeVoteNumber(final String subjectName) {
- return subjectVoteNumber(subjectName, Value.I_DONT_LIKE);
- }
-
- private int subjectVoteNumber(final String subjectName, final Value value) {
- return em.createNamedQuery(Subject.COUNT_VOTE, Number.class)
- .setParameter("name", subjectName)
- .setParameter("value", value)
- .getSingleResult().intValue();
- }
-
- private <T> T retrieve(final T object, final Class<T> clazz, long id) {
- if (em.contains(object)) {
- return object;
- }
-
- final T t = em.find(clazz, id);
- if (t == null) {
- throw new IllegalArgumentException(clazz.getSimpleName() + " not found");
- }
- return t;
- }
-
- public Subject bestSubject() {
- int bestScore = 0;
- Subject best = null;
- for (Subject subject : findAll()) {
- int currentScore = subject.score();
- if (best == null || bestScore < currentScore) {
- bestScore = currentScore;
- best = subject;
- }
- }
- return best;
- }
-
- @Singleton
- @Lock(LockType.READ)
- @PersistenceContext(name = "polling")
- public static interface ReadSubjectDao {
-
- Subject findByName(final String name);
-
- Collection<Subject> findAll();
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.dao;
+
+import jug.domain.Subject;
+import jug.domain.Value;
+import jug.domain.Vote;
+
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import java.util.Collection;
+
+@Singleton
+@Lock(LockType.READ)
+public class SubjectDao {
+
+ @PersistenceContext(unitName = "polling")
+ private EntityManager em;
+
+ @Inject
+ private ReadSubjectDao readDao;
+
+ public Subject create(final String name, final String question) {
+ final Subject subject = new Subject();
+ subject.setName(name);
+ subject.setQuestion(question);
+
+ em.persist(subject);
+ return subject;
+ }
+
+ public Subject addVote(final Subject subject, final Vote vote) {
+ final Vote foundVote = retrieve(vote, Vote.class, vote.getId());
+ final Subject subjectToUpdate = retrieve(subject, Subject.class, subject.getId());
+
+ subjectToUpdate.getVotes().add(foundVote);
+ return subjectToUpdate;
+ }
+
+ public Subject findByName(final String name) {
+ return readDao.findByName(name);
+ }
+
+ public Collection<Subject> findAll() {
+ return readDao.findAll();
+ }
+
+ public int subjectLikeVoteNumber(final String subjectName) {
+ return subjectVoteNumber(subjectName, Value.I_LIKE);
+ }
+
+ public int subjectNotLikeVoteNumber(final String subjectName) {
+ return subjectVoteNumber(subjectName, Value.I_DONT_LIKE);
+ }
+
+ private int subjectVoteNumber(final String subjectName, final Value value) {
+ return em.createNamedQuery(Subject.COUNT_VOTE, Number.class)
+ .setParameter("name", subjectName)
+ .setParameter("value", value)
+ .getSingleResult().intValue();
+ }
+
+ private <T> T retrieve(final T object, final Class<T> clazz, long id) {
+ if (em.contains(object)) {
+ return object;
+ }
+
+ final T t = em.find(clazz, id);
+ if (t == null) {
+ throw new IllegalArgumentException(clazz.getSimpleName() + " not found");
+ }
+ return t;
+ }
+
+ public Subject bestSubject() {
+ int bestScore = 0;
+ Subject best = null;
+ for (Subject subject : findAll()) {
+ int currentScore = subject.score();
+ if (best == null || bestScore < currentScore) {
+ bestScore = currentScore;
+ best = subject;
+ }
+ }
+ return best;
+ }
+
+ @Singleton
+ @Lock(LockType.READ)
+ @PersistenceContext(name = "polling")
+ public static interface ReadSubjectDao {
+
+ Subject findByName(final String name);
+
+ Collection<Subject> findAll();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-core/src/main/java/jug/dao/VoteDao.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-core/src/main/java/jug/dao/VoteDao.java b/examples/polling-parent/polling-core/src/main/java/jug/dao/VoteDao.java
index 40ca37d..7466fca 100644
--- a/examples/polling-parent/polling-core/src/main/java/jug/dao/VoteDao.java
+++ b/examples/polling-parent/polling-core/src/main/java/jug/dao/VoteDao.java
@@ -1,42 +1,42 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.dao;
-
-import jug.domain.Value;
-import jug.domain.Vote;
-
-import javax.ejb.Lock;
-import javax.ejb.LockType;
-import javax.ejb.Singleton;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-@Singleton
-@Lock(LockType.READ)
-public class VoteDao {
-
- @PersistenceContext(unitName = "polling")
- private EntityManager em;
-
- public Vote create(final Value voteValue) {
- final Vote vote = new Vote();
- vote.setValue(voteValue);
-
- em.persist(vote);
- return vote;
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.dao;
+
+import jug.domain.Value;
+import jug.domain.Vote;
+
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+@Singleton
+@Lock(LockType.READ)
+public class VoteDao {
+
+ @PersistenceContext(unitName = "polling")
+ private EntityManager em;
+
+ public Vote create(final Value voteValue) {
+ final Vote vote = new Vote();
+ vote.setValue(voteValue);
+
+ em.persist(vote);
+ return vote;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-core/src/test/java/jug/dao/SubjectDaoTest.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-core/src/test/java/jug/dao/SubjectDaoTest.java b/examples/polling-parent/polling-core/src/test/java/jug/dao/SubjectDaoTest.java
index 74ef984..9c84ab1 100644
--- a/examples/polling-parent/polling-core/src/test/java/jug/dao/SubjectDaoTest.java
+++ b/examples/polling-parent/polling-core/src/test/java/jug/dao/SubjectDaoTest.java
@@ -1,99 +1,99 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.dao;
-
-import jug.domain.Subject;
-import jug.domain.Value;
-import jug.domain.Vote;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import javax.ejb.embeddable.EJBContainer;
-import javax.inject.Inject;
-import javax.naming.NamingException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-public class SubjectDaoTest {
-
- private static EJBContainer container;
-
- @Inject
- private SubjectDao subjectDao;
-
- @Inject
- private VoteDao voteDao;
-
- @BeforeClass
- public static void start() {
- container = EJBContainer.createEJBContainer();
- }
-
- @Before
- public void inject() throws NamingException {
- container.getContext().bind("inject", this);
- }
-
- @AfterClass
- public static void stop() {
- container.close();
- }
-
- @Test
- public void persistSimpleSubject() {
- final Subject subject = subjectDao.create("TOMEE_JUG", "What do you think about this JUG?");
- assertNotNull(subject);
- assertEquals("TOMEE_JUG", subject.getName());
- }
-
- @Test
- public void playWithVotes() {
- Subject subject = subjectDao.create("TOMEE_JUG_2", "What do you think about this JUG?");
-
- final Vote vote = voteDao.create(Value.I_LIKE);
- subject = subjectDao.addVote(subject, vote);
- assertEquals(1, subject.getVotes().size());
-
- final Vote moreVote = voteDao.create(Value.I_LIKE);
- subject = subjectDao.addVote(subject, moreVote);
- assertEquals(2, subject.getVotes().size());
-
- final Vote notLiked = voteDao.create(Value.I_DONT_LIKE);
- subject = subjectDao.addVote(subject, notLiked);
- assertEquals(3, subject.getVotes().size());
-
- final Subject retrievedSubject = subjectDao.findByName("TOMEE_JUG_2");
- assertNotNull(retrievedSubject);
- assertNotNull(retrievedSubject.getVotes());
- assertEquals(3, retrievedSubject.getVotes().size());
- }
-
- @Test
- public void voteNumber() {
- final Subject subject = subjectDao.create("TOMEE_JUG_3", "What do you think about this JUG?");
-
- subjectDao.addVote(subject, voteDao.create(Value.I_LIKE));
- subjectDao.addVote(subject, voteDao.create(Value.I_LIKE));
- subjectDao.addVote(subject, voteDao.create(Value.I_DONT_LIKE));
-
- assertEquals(2, subjectDao.subjectLikeVoteNumber("TOMEE_JUG_3"));
- assertEquals(1, subjectDao.subjectNotLikeVoteNumber("TOMEE_JUG_3"));
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.dao;
+
+import jug.domain.Subject;
+import jug.domain.Value;
+import jug.domain.Vote;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.inject.Inject;
+import javax.naming.NamingException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class SubjectDaoTest {
+
+ private static EJBContainer container;
+
+ @Inject
+ private SubjectDao subjectDao;
+
+ @Inject
+ private VoteDao voteDao;
+
+ @BeforeClass
+ public static void start() {
+ container = EJBContainer.createEJBContainer();
+ }
+
+ @Before
+ public void inject() throws NamingException {
+ container.getContext().bind("inject", this);
+ }
+
+ @AfterClass
+ public static void stop() {
+ container.close();
+ }
+
+ @Test
+ public void persistSimpleSubject() {
+ final Subject subject = subjectDao.create("TOMEE_JUG", "What do you think about this JUG?");
+ assertNotNull(subject);
+ assertEquals("TOMEE_JUG", subject.getName());
+ }
+
+ @Test
+ public void playWithVotes() {
+ Subject subject = subjectDao.create("TOMEE_JUG_2", "What do you think about this JUG?");
+
+ final Vote vote = voteDao.create(Value.I_LIKE);
+ subject = subjectDao.addVote(subject, vote);
+ assertEquals(1, subject.getVotes().size());
+
+ final Vote moreVote = voteDao.create(Value.I_LIKE);
+ subject = subjectDao.addVote(subject, moreVote);
+ assertEquals(2, subject.getVotes().size());
+
+ final Vote notLiked = voteDao.create(Value.I_DONT_LIKE);
+ subject = subjectDao.addVote(subject, notLiked);
+ assertEquals(3, subject.getVotes().size());
+
+ final Subject retrievedSubject = subjectDao.findByName("TOMEE_JUG_2");
+ assertNotNull(retrievedSubject);
+ assertNotNull(retrievedSubject.getVotes());
+ assertEquals(3, retrievedSubject.getVotes().size());
+ }
+
+ @Test
+ public void voteNumber() {
+ final Subject subject = subjectDao.create("TOMEE_JUG_3", "What do you think about this JUG?");
+
+ subjectDao.addVote(subject, voteDao.create(Value.I_LIKE));
+ subjectDao.addVote(subject, voteDao.create(Value.I_LIKE));
+ subjectDao.addVote(subject, voteDao.create(Value.I_DONT_LIKE));
+
+ assertEquals(2, subjectDao.subjectLikeVoteNumber("TOMEE_JUG_3"));
+ assertEquals(1, subjectDao.subjectNotLikeVoteNumber("TOMEE_JUG_3"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-domain/src/main/java/jug/domain/Result.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-domain/src/main/java/jug/domain/Result.java b/examples/polling-parent/polling-domain/src/main/java/jug/domain/Result.java
index 7d52fd1..bc6e567 100644
--- a/examples/polling-parent/polling-domain/src/main/java/jug/domain/Result.java
+++ b/examples/polling-parent/polling-domain/src/main/java/jug/domain/Result.java
@@ -1,67 +1,67 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.domain;
-
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-
-@XmlRootElement
-@XmlType(propOrder = {
- "likes",
- "unlikes",
- "sum"
-})
-public class Result {
-
- private int likes;
- private int unlikes;
- private int sum;
-
- public Result() {
- // no-op
- }
-
- public Result(int likes, int unlikes) {
- this.likes = likes;
- this.unlikes = -Math.abs(unlikes);
- sum = likes + unlikes;
- }
-
- public int getLikes() {
- return likes;
- }
-
- public void setLikes(int likes) {
- this.likes = likes;
- }
-
- public int getUnlikes() {
- return unlikes;
- }
-
- public void setUnlikes(int unlikes) {
- this.unlikes = unlikes;
- }
-
- public int getSum() {
- return sum;
- }
-
- public void setSum(int sum) {
- this.sum = sum;
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.domain;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlType(propOrder = {
+ "likes",
+ "unlikes",
+ "sum"
+})
+public class Result {
+
+ private int likes;
+ private int unlikes;
+ private int sum;
+
+ public Result() {
+ // no-op
+ }
+
+ public Result(int likes, int unlikes) {
+ this.likes = likes;
+ this.unlikes = -Math.abs(unlikes);
+ sum = likes + unlikes;
+ }
+
+ public int getLikes() {
+ return likes;
+ }
+
+ public void setLikes(int likes) {
+ this.likes = likes;
+ }
+
+ public int getUnlikes() {
+ return unlikes;
+ }
+
+ public void setUnlikes(int unlikes) {
+ this.unlikes = unlikes;
+ }
+
+ public int getSum() {
+ return sum;
+ }
+
+ public void setSum(int sum) {
+ this.sum = sum;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-domain/src/main/java/jug/domain/Subject.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-domain/src/main/java/jug/domain/Subject.java b/examples/polling-parent/polling-domain/src/main/java/jug/domain/Subject.java
index dfe41ca..ec78b4d 100644
--- a/examples/polling-parent/polling-domain/src/main/java/jug/domain/Subject.java
+++ b/examples/polling-parent/polling-domain/src/main/java/jug/domain/Subject.java
@@ -1,106 +1,106 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.domain;
-
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.OneToMany;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.util.ArrayList;
-import java.util.Collection;
-
-@Entity
-@NamedQueries({
- @NamedQuery(name = Subject.FIND_ALL, query = "select s from Subject s"),
- @NamedQuery(name = Subject.FIND_BY_NAME_QUERY, query = "select s from Subject s where s.name = :name"),
- @NamedQuery(name = Subject.COUNT_VOTE, query = "select count(s) from Subject s left join s.votes v where v.value = :value and :name = s.name")
- })
-@XmlRootElement
-public class Subject {
-
- public static final String FIND_BY_NAME_QUERY = "Subject.findByName";
- public static final String COUNT_VOTE = "Subject.countVoteNumber";
- public static final String FIND_ALL = "Subject.findAll";
-
- @Id
- @GeneratedValue
- private long id;
-
- private String name;
-
- private String question;
-
- @OneToMany(fetch = FetchType.EAGER)
- private Collection<Vote> votes = new ArrayList<Vote>();
-
- public Subject() {
- // no-op
- }
-
- public Subject(String name, String question) {
- this.name = name;
- this.question = question;
- }
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getQuestion() {
- return question;
- }
-
- public void setQuestion(String question) {
- this.question = question;
- }
-
- public Collection<Vote> getVotes() {
- return votes;
- }
-
- public void setVotes(Collection<Vote> votes) {
- this.votes = votes;
- }
-
- public int score() {
- int s = 0;
- for (Vote vote : votes) {
- if (vote.getValue().equals(Value.I_LIKE)) {
- s++;
- } else {
- s--;
- }
- }
- return s;
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.domain;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.Collection;
+
+@Entity
+@NamedQueries({
+ @NamedQuery(name = Subject.FIND_ALL, query = "select s from Subject s"),
+ @NamedQuery(name = Subject.FIND_BY_NAME_QUERY, query = "select s from Subject s where s.name = :name"),
+ @NamedQuery(name = Subject.COUNT_VOTE, query = "select count(s) from Subject s left join s.votes v where v.value = :value and :name = s.name")
+})
+@XmlRootElement
+public class Subject {
+
+ public static final String FIND_BY_NAME_QUERY = "Subject.findByName";
+ public static final String COUNT_VOTE = "Subject.countVoteNumber";
+ public static final String FIND_ALL = "Subject.findAll";
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+ private String name;
+
+ private String question;
+
+ @OneToMany(fetch = FetchType.EAGER)
+ private Collection<Vote> votes = new ArrayList<Vote>();
+
+ public Subject() {
+ // no-op
+ }
+
+ public Subject(String name, String question) {
+ this.name = name;
+ this.question = question;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getQuestion() {
+ return question;
+ }
+
+ public void setQuestion(String question) {
+ this.question = question;
+ }
+
+ public Collection<Vote> getVotes() {
+ return votes;
+ }
+
+ public void setVotes(Collection<Vote> votes) {
+ this.votes = votes;
+ }
+
+ public int score() {
+ int s = 0;
+ for (Vote vote : votes) {
+ if (vote.getValue().equals(Value.I_LIKE)) {
+ s++;
+ } else {
+ s--;
+ }
+ }
+ return s;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-domain/src/main/java/jug/domain/Value.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-domain/src/main/java/jug/domain/Value.java b/examples/polling-parent/polling-domain/src/main/java/jug/domain/Value.java
index 518142a..c667d6a 100644
--- a/examples/polling-parent/polling-domain/src/main/java/jug/domain/Value.java
+++ b/examples/polling-parent/polling-domain/src/main/java/jug/domain/Value.java
@@ -1,22 +1,22 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.domain;
-
-public enum Value {
- I_LIKE,
- I_DONT_LIKE;
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.domain;
+
+public enum Value {
+ I_LIKE,
+ I_DONT_LIKE;
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-domain/src/main/java/jug/domain/Vote.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-domain/src/main/java/jug/domain/Vote.java b/examples/polling-parent/polling-domain/src/main/java/jug/domain/Vote.java
index 605f66d..44f1684 100644
--- a/examples/polling-parent/polling-domain/src/main/java/jug/domain/Vote.java
+++ b/examples/polling-parent/polling-domain/src/main/java/jug/domain/Vote.java
@@ -1,52 +1,52 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.domain;
-
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.xml.bind.annotation.XmlRootElement;
-
-@Entity
-@XmlRootElement
-public class Vote {
-
- @Id
- @GeneratedValue
- private long id;
-
- @Enumerated(EnumType.STRING)
- private Value value;
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public Value getValue() {
- return value;
- }
-
- public void setValue(Value value) {
- this.value = value;
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.domain;
+
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@Entity
+@XmlRootElement
+public class Vote {
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @Enumerated(EnumType.STRING)
+ private Value value;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public Value getValue() {
+ return value;
+ }
+
+ public void setValue(Value value) {
+ this.value = value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-web/src/main/java/jug/monitoring/VoteCounter.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-web/src/main/java/jug/monitoring/VoteCounter.java b/examples/polling-parent/polling-web/src/main/java/jug/monitoring/VoteCounter.java
index 1883d92..d50bca5 100644
--- a/examples/polling-parent/polling-web/src/main/java/jug/monitoring/VoteCounter.java
+++ b/examples/polling-parent/polling-web/src/main/java/jug/monitoring/VoteCounter.java
@@ -1,60 +1,60 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.monitoring;
-
-import jug.domain.Subject;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.management.Description;
-import javax.management.MBean;
-import javax.management.ManagedAttribute;
-import javax.management.ManagedOperation;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-@MBean
-@ApplicationScoped
-@Description("count the number of vote by subject")
-public class VoteCounter {
-
- private final Map<String, Subject> subjects = new ConcurrentHashMap<String, Subject>();
-
- @ManagedAttribute
- @Description("number of poll created/updated in this instance")
- public int getSubjectNumber() {
- return subjects.size();
- }
-
- @ManagedOperation
- @Description("current score of the specified poll")
- public String names() {
- return subjects.keySet().toString();
- }
-
- @ManagedOperation
- @Description("current score of the specified poll")
- public String score(final String name) {
- if (subjects.containsKey(name)) {
- return Integer.toString(subjects.get(name).score());
- }
- return "poll not found";
- }
-
- public void putSubject(final Subject subject) {
- subjects.put(subject.getName(), subject);
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.monitoring;
+
+import jug.domain.Subject;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.management.Description;
+import javax.management.MBean;
+import javax.management.ManagedAttribute;
+import javax.management.ManagedOperation;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@MBean
+@ApplicationScoped
+@Description("count the number of vote by subject")
+public class VoteCounter {
+
+ private final Map<String, Subject> subjects = new ConcurrentHashMap<String, Subject>();
+
+ @ManagedAttribute
+ @Description("number of poll created/updated in this instance")
+ public int getSubjectNumber() {
+ return subjects.size();
+ }
+
+ @ManagedOperation
+ @Description("current score of the specified poll")
+ public String names() {
+ return subjects.keySet().toString();
+ }
+
+ @ManagedOperation
+ @Description("current score of the specified poll")
+ public String score(final String name) {
+ if (subjects.containsKey(name)) {
+ return Integer.toString(subjects.get(name).score());
+ }
+ return "poll not found";
+ }
+
+ public void putSubject(final Subject subject) {
+ subjects.put(subject.getName(), subject);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f1b8ad/examples/polling-parent/polling-web/src/main/java/jug/rest/PollingApplication.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-web/src/main/java/jug/rest/PollingApplication.java b/examples/polling-parent/polling-web/src/main/java/jug/rest/PollingApplication.java
index b9501c7..e2fc60d 100644
--- a/examples/polling-parent/polling-web/src/main/java/jug/rest/PollingApplication.java
+++ b/examples/polling-parent/polling-web/src/main/java/jug/rest/PollingApplication.java
@@ -1,32 +1,32 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 jug.rest;
-
-import javax.ws.rs.ApplicationPath;
-import javax.ws.rs.core.Application;
-import java.util.HashSet;
-import java.util.Set;
-
-@ApplicationPath("/api")
-public class PollingApplication extends Application {
-
- public Set<Class<?>> getClasses() {
- final Set<Class<?>> classes = new HashSet<Class<?>>();
- classes.add(SubjectService.class);
- return classes;
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 jug.rest;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+import java.util.HashSet;
+import java.util.Set;
+
+@ApplicationPath("/api")
+public class PollingApplication extends Application {
+
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(SubjectService.class);
+ return classes;
+ }
+}