📄 xbrlstoreimpl.java
字号:
/** * This implementation is not as strict as the XBRL 2.1 specification * requires but it is generally faster and delivers sensible results. * It will only fail if people use the same link role and arc role but * rely on arc or link element differences to distinguish networks.<br/><br/> * * Implementation strategy is:<br/> * 1. Get all extended link elements with the given link role.<br/> * 2. Get all arcs with the given arc role.<br/> * 3. Get all resources at the source of the arcs.<br/> * 4. Return only those source resources that that are not target resources also.<br/> * * @param linkRole the role on the extended links that contain the network arcs. * @param arcRole the arcrole on the arcs describing the network. * @return The list of fragments for each of the resources that is identified as a root * of the specified network (noting that a root resource is defined as a resource that is * at the source of one or more relationships in the network and that is not at the target * of any relationships in the network). * @throws XBRLException */ public FragmentList<Fragment> getNetworkRoots(String linkRole, String arcRole) throws XBRLException { // Get the links that contain the network declaring arcs. String linkQuery = "/"+ Constants.XBRLAPIPrefix+ ":" + "fragment[@type='org.xbrlapi.impl.ExtendedLinkImpl' and "+ Constants.XBRLAPIPrefix+ ":" + "data/*[@xlink:role='" + linkRole + "']]"; FragmentList<ExtendedLink> links = this.<ExtendedLink>query(linkQuery); // Get the arcs that declare the relationships in the network. // For each arc map the ids of the fragments at their sources and targets. HashMap<String,String> sourceIds = new HashMap<String,String>(); HashMap<String,String> targetIds = new HashMap<String,String>(); for (int i=0; i<links.getLength(); i++) { ExtendedLink link = links.getFragment(i); FragmentList<Arc> arcs = link.getArcs(); for (Arc arc: arcs) { if (arc.getArcrole().equals(arcRole)) { FragmentList<ArcEnd> sources = arc.getSourceFragments(); FragmentList<ArcEnd> targets = arc.getTargetFragments(); for (int k=0; k<sources.getLength(); k++) { sourceIds.put(sources.getFragment(k).getFragmentIndex(),""); } for (int k=0; k<sources.getLength(); k++) { targetIds.put(targets.getFragment(k).getFragmentIndex(),""); } } } } // Get the root resources in the network FragmentList<Fragment> roots = new FragmentListImpl<Fragment>(); Iterator<String> iterator = sourceIds.keySet().iterator(); while (iterator.hasNext()) { String id = iterator.next(); if (! targetIds.containsKey(id)) { roots.addFragment(this.getFragment(id)); } } return roots; } /** * @param namespace The namespace for the concept. * @param name The local name for the concept. * @return the concept fragment for the specified namespace and name. * @throws XBRLException if more than one matching concept is found in the data store * or if no matching concepts are found in the data store. */ public Concept getConcept(String namespace, String name) throws XBRLException { // TODO Make sure that non-concept element declarations are handled. FragmentList<Concept> concepts = this.<Concept>query("/"+ Constants.XBRLAPIPrefix+ ":" + "fragment/"+ Constants.XBRLAPIPrefix+ ":" + "data/xsd:element[@name='" + name + "']"); FragmentList<Concept> matches = new FragmentListImpl<Concept>(); for (Concept concept: concepts) { if (concept.getTargetNamespaceURI().equals(namespace)) { matches.addFragment(concept); } } if (matches.getLength() == 0) throw new XBRLException("No matching concepts were found for " + namespace + ":" + name + "."); if (matches.getLength() > 1) throw new XBRLException(new Integer(matches.getLength()) + "matching concepts were found for " + namespace + ":" + name + "."); return matches.getFragment(0); } /** * @see org.xbrlapi.data.XBRLStore#getLinkRoles() */ public HashMap<String,String> getLinkRoles() throws XBRLException { HashMap<String,String> roles = new HashMap<String,String>(); FragmentList<RoleType> types = this.getRoleTypes(); for (RoleType type: types) { String role = type.getCustomURI(); String query = "/"+ Constants.XBRLAPIPrefix+ ":" + "fragment[@type='org.xbrlapi.impl.ExtendedLinkImpl' and "+ Constants.XBRLAPIPrefix+ ":" + "data/*/@xlink:role='" + role + "']"; FragmentList<ExtendedLink> links = this.<ExtendedLink>query(query); if (links.getLength() > 0) { roles.put(role,""); } } return roles; } /** * @see org.xbrlapi.data.XBRLStore#getArcRoles() */ public HashMap<String,String> getArcRoles() throws XBRLException { // TODO Simplify getArcRoles method of the XBRLStore to eliminate need to get all arcs in the data store. HashMap<String,String> roles = new HashMap<String,String>(); FragmentList<ArcroleType> types = this.getArcroleTypes(); for (ArcroleType type: types) { String role = type.getCustomURI(); String query = "/"+ Constants.XBRLAPIPrefix + ":" + "fragment["+ Constants.XBRLAPIPrefix+ ":" + "data/*[@xlink:type='arc' and @xlink:arcrole='" + role + "']]"; FragmentList<Arc> arcs = this.<Arc>query(query); if (arcs.getLength() > 0) { roles.put(role,""); } } return roles; } /** * @see org.xbrlapi.data.XBRLStore#getLinkRoles(String) */ public HashMap<String,String> getLinkRoles(String arcrole) throws XBRLException { HashMap<String,String> roles = new HashMap<String,String>(); HashMap<String,Fragment> links = new HashMap<String,Fragment>(); String query = "/"+ Constants.XBRLAPIPrefix+ ":" + "fragment["+ Constants.XBRLAPIPrefix+ ":" + "data/*[@xlink:type='arc' and @xlink:arcrole='" + arcrole + "']]"; FragmentList<Arc> arcs = this.<Arc>query(query); for (Arc arc: arcs) { if (! links.containsKey(arc.getParentIndex())) { ExtendedLink link = arc.getExtendedLink(); links.put(link.getFragmentIndex(),link); } } for (Fragment l: links.values()) { ExtendedLink link = (ExtendedLink) l; if (! roles.containsKey(link.getLinkRole())) { roles.put(link.getLinkRole(),""); } } return roles; } /** * @return a list of roleType fragments * @throws XBRLException */ public FragmentList<RoleType> getRoleTypes() throws XBRLException { return this.<RoleType>getFragments("RoleType"); } /** * @see org.xbrlapi.data.XBRLStore#getRoleTypes(String) */ public FragmentList<RoleType> getRoleTypes(String uri) throws XBRLException { String query = "/"+ Constants.XBRLAPIPrefix+ ":" + "fragment["+ Constants.XBRLAPIPrefix+ ":" + "data/link:roleType/@roleURI='" + uri + "']"; return this.<RoleType>query(query); } /** * @return a list of ArcroleType fragments * @throws XBRLException */ public FragmentList<ArcroleType> getArcroleTypes() throws XBRLException { return this.<ArcroleType>getFragments("ArcroleType"); } /** * @return a list of arcroleType fragments that define a given arcrole. * @throws XBRLException */ public FragmentList<ArcroleType> getArcroleTypes(String uri) throws XBRLException { String query = "/"+ Constants.XBRLAPIPrefix+ ":" + "fragment["+ Constants.XBRLAPIPrefix+ ":" + "data/link:arcroleType/@arcroleURI='" + uri + "']"; return this.<ArcroleType>query(query); } /** * @see org.xbrlapi.data.XBRLStore#getResourceRoles() */ public HashMap<String,String> getResourceRoles() throws XBRLException { HashMap<String,String> roles = new HashMap<String,String>(); FragmentList<Resource> resources = this.<Resource>query("/"+ Constants.XBRLAPIPrefix+ ":" + "fragment["+ Constants.XBRLAPIPrefix+ ":" + "data/*/@xlink:type='resource']"); for (Resource resource: resources) { String role = resource.getResourceRole(); if (! roles.containsKey(role)) roles.put(role,""); } return roles; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -