]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/GlobalShare.java
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 package org
.tianocore
.build
.global
;
22 import org
.apache
.tools
.ant
.*;
23 import org
.apache
.tools
.ant
.types
.DataType
;
25 public class GlobalShare
extends DataType
implements DynamicConfigurator
{
26 private static final HashMap
<String
, Object
> objStorage
= new HashMap
<String
, Object
>();
28 private DataObjectOp op
;
30 private String objName
;
32 private Object objInst
;
34 private String objClassPackage
= "org.tianocore";
36 public GlobalShare () {
40 public GlobalShare (String objName
) {
41 this.objName
= objName
;
42 this.objInst
= objStorage
.get(this.objName
);
45 public GlobalShare (String objName
, Object obj
) {
46 this.objName
= objName
;
48 objStorage
.put(this.objName
, this.objInst
);
51 public Object
createDynamicElement(String name
) throws BuildException
{
52 String className
= objClassPackage
+ "." + name
;
53 log("GlobalShare.createDynamicElement(" + name
+ ")",
56 objInst
= Class
.forName(className
).newInstance();
57 } catch (ClassNotFoundException e
) {
58 throw new BuildException("class name is not found");
59 } catch (InstantiationException e
) {
60 throw new BuildException("the class cannnot be instantiated");
61 } catch (IllegalAccessException e
) {
62 throw new BuildException("cannot access the class");
68 public void setDynamicAttribute(String name
, String value
)
69 throws BuildException
{
70 log("name = " + name
+ " value = " + value
, Project
.MSG_VERBOSE
);
71 throw new BuildException();
74 public void setName(String name
) {
76 if (this.op
!= null) {
81 public String
getName() {
85 public void setPackage(String name
) {
86 log("ShareObject.setPackage(" + name
+ ")", Project
.MSG_VERBOSE
);
87 this.objClassPackage
= name
;
90 public String
getPackage() {
91 return this.objClassPackage
;
94 public void setOperation(String opName
) {
95 log("ShareObject.setOperation(" + opName
+ ")", Project
.MSG_VERBOSE
);
96 this.op
= DataObjectOp
.formString(opName
);
98 if (this.objName
!= null) {
103 public String
getOperation() {
104 return this.op
.toString();
107 public void issueOperation() {
108 if (this.op
== DataObjectOp
.ADD
) {
110 log("ShareObject: adding ... " + this.objName
, Project
.MSG_VERBOSE
);
111 objStorage
.put(this.objName
, this.objInst
);
113 } else if (this.op
== DataObjectOp
.GET
) {
115 log("ShareObject: fetching ... " + this.objName
,
116 Project
.MSG_VERBOSE
);
117 objInst
= objStorage
.get(objName
);
119 } else if (this.op
== DataObjectOp
.DEL
) {
121 log("ShareObject: removing ... " + this.objName
,
122 Project
.MSG_VERBOSE
);
123 objInst
= objStorage
.remove(objName
);
126 throw new BuildException("not supported operation");
130 public Object
get() {
134 public static int getObjectNum() {
135 return objStorage
.size();
138 public static Object
add(String objName
, Object obj
) {
139 return objStorage
.put(objName
, obj
);
142 public static Object
retrieve(String objName
) {
143 return objStorage
.get(objName
);
146 public static Object
remove(String objName
) {
147 return objStorage
.remove(objName
);
150 public static void empty() {
156 private static final HashMap
<String
, DataObjectOp
> opMap
= new HashMap
<String
, DataObjectOp
>();
158 private final String opName
;
160 private DataObjectOp (String name
) {
162 opMap
.put(this.opName
, this);
165 public String
toString() {
169 public static DataObjectOp
formString(String opName
) {
170 return opMap
.get(opName
);
173 public static final DataObjectOp ADD
= new DataObjectOp("ADD");
175 public static final DataObjectOp GET
= new DataObjectOp("GET");
177 public static final DataObjectOp DEL
= new DataObjectOp("DEL");