You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2014/11/10 14:29:27 UTC
git commit: [flex-utilities] [refs/heads/develop] - Moved some
generic code to the API
Repository: flex-utilities
Updated Branches:
refs/heads/develop 469e619c8 -> 3892850d5
Moved some generic code to the API
Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/3892850d
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/3892850d
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/3892850d
Branch: refs/heads/develop
Commit: 3892850d50ef0c71d5fcbf5369ef84e87a845dff
Parents: 469e619
Author: Christofer Dutz <ch...@codecentric.de>
Authored: Mon Nov 10 14:29:21 2014 +0100
Committer: Christofer Dutz <ch...@codecentric.de>
Committed: Mon Nov 10 14:29:21 2014 +0100
----------------------------------------------------------------------
.../flex/tools/AbstractFlexToolGroup.java | 63 ++++++++++++++++++++
.../org/apache/flex/tools/FlexToolRegistry.java | 58 ++++++++++++++++++
2 files changed, 121 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/3892850d/flex-tool-api/src/main/java/org/apache/flex/tools/AbstractFlexToolGroup.java
----------------------------------------------------------------------
diff --git a/flex-tool-api/src/main/java/org/apache/flex/tools/AbstractFlexToolGroup.java b/flex-tool-api/src/main/java/org/apache/flex/tools/AbstractFlexToolGroup.java
new file mode 100644
index 0000000..8608de5
--- /dev/null
+++ b/flex-tool-api/src/main/java/org/apache/flex/tools/AbstractFlexToolGroup.java
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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 org.apache.flex.tools;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Base class that can be used for any type of Tool groups.
+ */
+public abstract class AbstractFlexToolGroup implements FlexToolGroup {
+
+ private String name;
+ private Map<String, FlexTool> tools;
+
+ public AbstractFlexToolGroup(String name) {
+ this.name = name;
+ tools = new HashMap<String, FlexTool>();
+ }
+
+ protected void addFlexTool(FlexTool flexTool) {
+ tools.put(flexTool.getName(), flexTool);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Collection<String> getFlexToolNames() {
+ return tools.keySet();
+ }
+
+ @Override
+ public boolean hasFlexTool(String toolName) {
+ return tools.containsKey(toolName);
+ }
+
+ @Override
+ public FlexTool getFlexTool(String toolName) {
+ return tools.get(toolName);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/3892850d/flex-tool-api/src/main/java/org/apache/flex/tools/FlexToolRegistry.java
----------------------------------------------------------------------
diff --git a/flex-tool-api/src/main/java/org/apache/flex/tools/FlexToolRegistry.java b/flex-tool-api/src/main/java/org/apache/flex/tools/FlexToolRegistry.java
new file mode 100644
index 0000000..67b06de
--- /dev/null
+++ b/flex-tool-api/src/main/java/org/apache/flex/tools/FlexToolRegistry.java
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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 org.apache.flex.tools;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+/**
+ * Utility class for automatically detecting and initializing any
+ * flex tool group implementation available on the current classpath
+ * using Java ServiceLoaders.
+ */
+public class FlexToolRegistry {
+
+ private Map<String, FlexToolGroup> toolGroupMap;
+
+ public FlexToolRegistry() {
+ toolGroupMap = new HashMap<String, FlexToolGroup>();
+
+ // Locate and instantiate each tool group and save a reference to it.
+ ServiceLoader<FlexToolGroup> toolGroups = ServiceLoader.load(FlexToolGroup.class);
+ for(FlexToolGroup toolGroup : toolGroups) {
+ toolGroupMap.put(toolGroup.getName(), toolGroup);
+ }
+ }
+
+ public Collection<String> getToolGroupNames() {
+ return toolGroupMap.keySet();
+ }
+
+ public Collection<FlexToolGroup> getToolGroups() {
+ return toolGroupMap.values();
+ }
+
+ public FlexToolGroup getToolGroup(String toolGroupName) {
+ return toolGroupMap.get(toolGroupName);
+ }
+
+}