📄 fragmentimpl.java
字号:
FragmentList<ArcEnd> targets = arc.getTargetFragments();
for (ArcEnd end: targets) {
if (end.getType().equals("org.xbrlapi.impl.LocatorImpl")) {
Fragment target = ((Locator) end).getTargetFragment();
relationship = new RelationshipImpl(arc,this,target);
} else {
relationship = new RelationshipImpl(arc,this,end);
}
networks.addRelationship(relationship);
}
}
arcs = locator.getArcsToWithArcrole(arcrole);
for (Arc arc: arcs) {
FragmentList<ArcEnd> sources = arc.getSourceFragments();
for (ArcEnd end: sources) {
if (end.getType().equals("org.xbrlapi.impl.LocatorImpl")) {
Fragment source = ((Locator) end).getTargetFragment();
relationship = new RelationshipImpl(arc,source,this);
} else {
relationship = new RelationshipImpl(arc,end,this);
}
networks.addRelationship(relationship);
}
}
}
return networks;
}
/**
* @see org.xbrlapi.Fragment#isa(String)
*/
@SuppressWarnings("unchecked")
public boolean isa(String superType) throws XBRLException {
Class superClass = FragmentFactory.getClass(superType);
Class candidateClass = this.getClass();
while (candidateClass != null) {
if (candidateClass.equals(superClass)) return true;
candidateClass = candidateClass.getSuperclass();
}
return false;
}
/**
* @see org.xbrlapi.Fragment#getParentIndex()
*/
public String getParentIndex() throws XBRLException {
return getMetaAttribute("parentIndex");
}
/**
* @see org.xbrlapi.Fragment#setParentIndex(String)
*/
public void setParentIndex(String index) throws XBRLException {
setMetaAttribute("parentIndex",index);
}
/**
* @see org.xbrlapi.Fragment#getXPath()
*/
public String getXPath() throws XBRLException {
String value = getMetaAttribute("SequenceToParentElement");
if (value.equals("")) return ".";
String[] sequence = value.split(" ");
StringBuffer xpath = new StringBuffer(".");
for (int i=0; i<sequence.length; i++) {
xpath.append("/*[" + sequence[i] + "]");
}
return xpath.toString();
}
/**
* @see org.xbrlapi.Fragment#setSequenceToParentElement(Vector)
*/
public void setSequenceToParentElement(Vector<Long> children) throws XBRLException {
StringBuffer value = new StringBuffer("");
for (int i=0; i<children.size()-1; i++) {
String child = children.get(i).toString();
if (value.length() == 0) {
value.append(child);
} else {
value.append(" " + child);
}
}
setMetaAttribute("SequenceToParentElement",value.toString());
}
/**
* @see org.xbrlapi.Fragment#getSequenceToParentElement()
*/
public String[] getSequenceToParentElement() throws XBRLException {
return this.getSequenceToParentElementAsString().split(" ");
}
/**
* @see org.xbrlapi.Fragment#getSequenceToParentElementAsString()
*/
public String getSequenceToParentElementAsString() throws XBRLException {
String value = this.getMetaAttribute("SequenceToParentElement");
if (value == null) return "";
return value;
}
/**
* @see org.xbrlapi.Fragment#getPrecedingSiblings()
*/
public String getPrecedingSiblings() throws XBRLException {
return getMetaAttribute("precedingSiblings");
}
/**
* @see org.xbrlapi.Fragment#setPrecedingSiblings(Vector)
*/
public void setPrecedingSiblings(Vector<Long> children) throws XBRLException {
Long value = new Long((children.get(children.size()-1)).longValue() - 1);
String precedingSiblings = value.toString();
setMetaAttribute("precedingSiblings",precedingSiblings);
}
/**
* @see org.xbrlapi.Fragment#removeRelationship(String)
*/
public void removeRelationship(String index) throws XBRLException {
HashMap<String,String> attributes = new HashMap<String,String>();
attributes.put("targetIndex",index);
removeMetadataElement("xlinkRelationship",attributes);
}
/**
* @see org.xbrlapi.Fragment#appendID(String)
* TODO Eliminate the ID metadata element given the existence of the xptr elements.
*/
public void appendID(String id) throws XBRLException {
HashMap<String,String> attributes = new HashMap<String,String>();
attributes.put("id",id);
appendMetadataElement("ID",attributes);
}
/**
* @see org.xbrlapi.Fragment#removeID(String)
* TODO remove the redundant parameter from this method.
*/
public void removeID(String id) throws XBRLException {
HashMap<String,String> attributes = new HashMap<String,String>();
attributes.put("ID",id);
removeMetadataElement("ID",attributes);
}
/**
* @see org.xbrlapi.Fragment#appendElementSchemeXPointer(String)
*/
public void appendElementSchemeXPointer(String expression) throws XBRLException {
HashMap<String,String> attributes = new HashMap<String,String>();
attributes.put("value",expression);
appendMetadataElement("xptr",attributes);
}
/**
* @see org.xbrlapi.Fragment#removeElementSchemeXPointer(String)
*/
public void removeElementSchemeXPointer(String expression) throws XBRLException {
HashMap<String,String> attributes = new HashMap<String,String>();
attributes.put("value",expression);
removeMetadataElement("xptr",attributes);
}
/**
* @see org.xbrlapi.Fragment#getNamespaceURI()
*/
public String getNamespaceURI() throws XBRLException {
if (getDataRootElement() == null) {
throw new XBRLException("The XML fragment root node is null.");
}
return getDataRootElement().getNamespaceURI();
}
/**
* @see org.xbrlapi.Fragment#getLocalname()
*/
public String getLocalname() throws XBRLException {
return getDataRootElement().getLocalName();
}
/**
* @see org.xbrlapi.Fragment#getPrefixFromQName(String)
*/
public String getPrefixFromQName(String qname) {
// Get the required namespace prefix from the QName
String prefix = "";
int delimiterIndex = qname.indexOf(':');
if (delimiterIndex > 0) {
prefix = qname.substring(0,delimiterIndex);
}
return prefix;
}
/**
* @see org.xbrlapi.Fragment#getNamespaceFromQName(String, Node)
*/
public String getNamespaceFromQName(String qname, Node node) throws XBRLException {
// Create NS prefix declaration for the QName being sought.
String prefix = getPrefixFromQName(qname);
String declaration = "xmlns";
if (!prefix.equals("")) {
declaration = declaration + ":" + prefix;
}
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
// Check for a namespace declaration on the current node
String ns = element.getAttribute(declaration);
if (! ns.equals("")) {
return ns;
}
if (element.isSameNode(this.getMetadataRootElement())) {
throw new XBRLException("the QName prefix is not declared for " + qname);
} else {
return getNamespaceFromQName(qname, element.getParentNode());
}
} else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
Node parent = node.getParentNode();
if (parent == null) throw new XBRLException("No namespace is defined for QName " + qname);
return getNamespaceFromQName(qname, parent);
} else {
throw new XBRLException("An element node is expected.");
}
}
/**
* @see org.xbrlapi.Fragment#getParent()
*/
public Fragment getParent() throws XBRLException {
String parentIndex = this.getParentIndex();
if (parentIndex == null) return null;
return getStore().getFragment(parentIndex);
}
/**
* @see org.xbrlapi.Fragment#getParentElement(Element)
*/
public Element getParentElement(Element parentDataRootElement) throws XBRLException {
String[] sequence = getSequenceToParentElement();
if (sequence[0].equals("")) {
return parentDataRootElement;
}
// Traverse the parent data DOM to find the parent element
Element current = parentDataRootElement;
for (int i=0; i<sequence.length; i++) { // Iterate the sequence of steps through the parent fragment
int elementOrder = (new Integer(sequence[i])).intValue(); // The sibling position
int elementsFound = 0;
NodeList children = current.getChildNodes();
int j = 0;
while ((elementsFound < elementOrder) && (j < children.getLength())) {
Node child = children.item(j);
if (child.getNodeType() == Node.ELEMENT_NODE) {
elementsFound++;
if (elementsFound == elementOrder) current = (Element) child;
}
j++;
}
if ((j==children.getLength()) && (elementsFound < elementOrder)) {
throw new XBRLException("The sequence to the parent element is incorrect.");
}
}
return current;
}
/**
* @see org.xbrlapi.Fragment#getLocalnameFromQName(String)
*/
public String getLocalnameFromQName(String qname) {
String localname = "";
int delimiterIndex = qname.indexOf(':');
if (delimiterIndex > 0) {
localname = qname.substring(delimiterIndex+1,qname.length());
}
return localname;
}
/**
* @see org.xbrlapi.Fragment#hashCode()
*/
public int hashCode() {
return getFragmentIndex().hashCode();
}
/**
* @see org.xbrlapi.Fragment#equals(Object)
*/
public boolean equals(Object o1) throws ClassCastException {
Fragment f1 = (Fragment) o1;
if (this.getFragmentIndex().equals(f1.getFragmentIndex()))
return true;
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -